Forum: Ruby Problem with regex using mx flags

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5730f209b34b8474639e0c2020f54513?d=identicon&s=25 Dan Kohn (Guest)
on 2005-12-22 00:06
(Received via mailing list)
Could you please take a look at this regex (line 52) that's just
killing me. (It's at <http://rafb.net/paste/results/l4U66N90.html> or
below).  When I split it up (lines 44-49) it works fine. There must be
something obvious but I can't see it.

doc = <<EOF
      <Placemark>
        <!--NOBBS-->
        <name>KSFO</name>
        <Point>
          <coordinates>-122.374889,37.618972</coordinates>
        </Point>
        <LookAt>
          <longitude>-122.374889</longitude>
          <latitude>37.618972</latitude>
          <range>100000.0</range>
        </LookAt>
        <styleUrl>#iata</styleUrl>
        <description>
          <![CDATA[<h3>San Francisco Intl,
Usa</h3><table><tr><td>ICAO:</td><td>KSFO</td></tr><tr><td>IATA:</td><td>SFO</td></tr><tr><td>Altitude:</td><td>
  13
ft.</td></tr><tr><td>Type:</td><td>Civil</td></tr><tr><td>Rwy&nbsp;19L/01R:</td><td>193.0&deg;/13.0&deg;&nbsp;&nbsp;8648ft.,&nbsp;Alt.&nbsp;10.0ft.</td></tr><tr><td>Rwy&nbsp;19R/01L:</td><td>193.0&deg;/13.0&deg;&nbsp;&nbsp;7500ft.,&nbsp;Alt.&nbsp;8.8ft.</td></tr><tr><td>Rwy&nbsp;28L/10R:</td><td>283.0&deg;/103.0&deg;&nbsp;10602ft.,&nbsp;Alt.&nbsp;12.7ft.</td></tr><tr><td>Rwy&nbsp;28R/10L:</td><td>283.0&deg;/103.0&deg;&nbsp;11870ft.,&nbsp;Alt.&nbsp;13.1ft.</td></tr><tr><td>Timezone:</td><td>UTC-8(-7DT)</td></tr><tr><td>DAFIF&nbsp;Cycle:</td><td>200510</td></tr><tr><td></td><td></td></tr><tr><td>CAUTION</td><td>WIP
UFN apch end Rwy 28L/R and 19L. Bird haz. Rubber accumulated first
3000' Rwy28L and 28R. Pilots shall strictly flw nose-gear lines, no
oversteering adjustment perms. Several rwy hold posn signs on rgt side
of twy.</td></tr><tr><td>CG</td><td>Min 24 hr PPR exc CG msn,
C650-808-2901/2902 dur nml duty hr 1600-2400Z++. Svc ltd to prk, ramp
space only, C-12/C-20 or smaller. No fuel, messing, space A svc,govt
sfc transportation, tran qtrs, maint. 15 min before arr ctc SAN FRAN
AIR
3</td></tr><tr><td>CG</td><td>81.8.</td></tr><tr><td>FUEL</td><td>(NC-100,
100LL, A)</td></tr><tr><td>LGT</td><td>Rwy 19L SALSF are only 1100'
long with only one flasher on the last lgt
stn.</td></tr><tr><td>MISC</td><td>Rwy 01R-19L, 10R-28L, 10L-28R
grooved exc at rwy int. Rwy 01L-19R grooved exc atrwy int and 535' N of
Twy C. Hi speed Twy T grooved btn Rwy 28R and 28L. Copterldg area mrk
on Twy C in front of Coast Guard OPS for mil use only. Rwy 10
pref</td></tr><tr><td>MISC</td><td>rwy 0900-1400Z++, wx and cond perms.
Flt Notification Svc, ADCUS, avbl.
LLWAS.</td></tr><tr><td>NS&nbsp;ABTMT</td><td>For pro fone
C650-821-5100, 1600-0100Z++ Mon-Fri.</td></tr><tr><td>RSTD</td><td>Taxi
speed less than 10 Kt per hr on non-rstd twy trml side of rwy int, less
than 5 Kt per hr when B747-400 pass on Twy A or
B.</td></tr><tr><td>TFC&nbsp;PAT</td><td>Rgt tfc Rwy 10R,
28R.</td></tr></table>]]>
        </description>
        <Snippet>
          <![CDATA[San Francisco Intl (SFO)]]>
        </Snippet>
      </Placemark>
      <Placemark>
        <!--NOBBS-->
        <name>PHOG</name>
        <Point>
          <coordinates>-156.430458,20.898650</coordinates>
        </Point>
        <LookAt>
          <longitude>-156.430458</longitude>
          <latitude>20.898650</latitude>
          <range>100000.0</range>
        </LookAt>
        <styleUrl>#iata</styleUrl>
        <description>
          <![CDATA[<h3>Kahului, Usa Maui
Isl.</h3><table><tr><td>ICAO:</td><td>PHOG</td></tr><tr><td>IATA:</td><td>OGG</td></tr><tr><td>Altitude:</td><td>
  54
ft.</td></tr><tr><td>Type:</td><td>Civil</td></tr><tr><td>Rwy&nbsp;20/02:</td><td>205.0&deg;/25.0&deg;&nbsp;&nbsp;6995ft.,&nbsp;Alt.&nbsp;12.4ft.</td></tr><tr><td>Rwy&nbsp;23/05:</td><td>235.0&deg;/55.0&deg;&nbsp;&nbsp;4990ft.,&nbsp;Alt.&nbsp;15.9ft.</td></tr><tr><td>Island/Group:</td><td>Maui
I</td></tr><tr><td>Timezone:</td><td>UTC-10</td></tr><tr><td>DAFIF&nbsp;Cycle:</td><td>200505</td></tr><tr><td></td><td></td></tr><tr><td>CAUTION</td><td>Lgtd
twr 570' hi 3 NM W of arpt. Bird haz. Due to non-vis twr unable to
determine if the flw areas are clear of obst/tfc; portion of Twy F btn
commuter trml andapch end Rwy 05. Due to non-vis twr unable to provide
svc btn acft/veh on commu</td></tr><tr><td>CAUTION</td><td>ter trml S
of Twy F and copter trml E of apch end Rwy 02. 130' crane 6000' SW apch
end Rwy 02.</td></tr><tr><td>FUEL</td><td>A+ (Air Service Hawaii,
1700-0400Z, C808-871-5572; OT 1.5 hr PN rqr, C808-870-8007
C808-757-0321, $100 fee.) (NC-100-Avbl  24 hr
self-svc).</td></tr><tr><td>LGT</td><td>When twr is unattended,
ACTIVATE-MALSR Rwy 02, HIRL Rwy 02-20 and MIRL Rwy 05-23-CTAF. VASI Rwy
02 TCH 65', Rwy 20 TCH 76', Rwy 05 TCH 40'. VASI Rwy 05 unuse byd 4 NM
due rising terrain.</td></tr><tr><td>MISC</td><td>Crash and fire eqpt
avbl 24 hr. All rwy grooved. LLWAS 0000-0900Z. LAWRS
1600-0900Z.</td></tr><tr><td>NS&nbsp;ABTMT</td><td>See ARR/DEP GRAPHICS
Sec E.</td></tr><tr><td>RSTD</td><td>24 hr PPR for Class A and B
explosives and 4 hr PPR for other haz cargo in/out of arpt, fone
C808-872-3830 1745-0230Z, OT C808-872-3888. Portions of commuter and
scenic flt opr not vis fr twr. Commuter trml ramp rstd to acft 140,000
lb or l</td></tr><tr><td>RSTD</td><td>ess. Mil copter opr rstd to haz
material area N Rwy 05-23. Area E of apch end Rwy 02 designated as
copter opr area. No F/W acft may opr on helipad. PPR for F/W opr on
helipad C808-872-3880 1515-0800Z. Access to helipad fr Twy C only. Ramp
a</td></tr><tr><td>RSTD</td><td>rea E side of Rwy 02 under state auth.
FAA not responsible for drct and ctl of gnd tfc in area. Tran prk lctd
on NE sec of E ramp.</td></tr></table>]]>
        </description>
        <Snippet>
          <![CDATA[Kahului (OGG)]]>
        </Snippet>
      </Placemark>
EOF

doc.scan(/<Placemark>(.*?)<\/Placemark>/m) { |e|
  s = e.to_s
  s =~ /<longitude>(.*?)<\/longitude>/m
  long = $1
  s =~ /<latitude>(.*?)<\/latitude>/m
  lat = $1
  s =~ /IATA:.*?([A-Z0-9]{3})[^A-Z0-9]/m
  code = $1
  p "line: " + long + ":" + lat + ":" + code

  s.match(  /<longitude>(.*?)<\/longitude>.*?
                  <latitude>(.*?)<\/latitude>.*?
                  IATA:.*?([A-Z0-9]{3})[^A-Z0-9]/mx
    ) { |match|
      p "match: " + $1 + ":" + $2 + ":" + $3
      }

  }
5730f209b34b8474639e0c2020f54513?d=identicon&s=25 Dan Kohn (Guest)
on 2005-12-25 16:15
(Received via mailing list)
Sorry, that was silly.  I was using m.match when I needed s.scan.
This topic is locked and can not be replied to.