Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Regexp Problem with greedy

by asarih (Hermit)
on Sep 11, 2003 at 00:08 UTC ( #290563=note: print w/replies, xml ) Need Help??

in reply to Regexp Problem with greedy

A fundamental problem with this script is that it is chopping a file at each \n. If a tagged text spans more than one line, you won't catch it. Do you want to catch the <M> tags only if its ending tag has digits?

This will do it. (I'll leave it up to you to improve it so that it can detect tagged text that spans over line breaks.)

#!/usr/local/bin/perl -w while (<DATA>) { for (m{<M>([^<]+)(?=</M\d+>)}ig) { print $_,"\n"}; } __DATA__ America's first <M>swept-wing</M>, <M>multiengine jet</M> <M>bomber</M +> was the <M>B-47 Stratojet</M200>, and the first <M>swept-wing fighter</M> was the <M>F-86 Sabre Jet</M201>. Both used new swept-wing data found in Germany after <M>World War II</M> and sent back to the United States by American scientists. This photograph, from <D>1951</D +>, was taken the first time the two flew together over <PL>Kansas</PL>. <M>Bogus</M2> <M>airplane</M3>
But you really should read perlre and if you get a chance, by all means read Jeff Friedl's excellent Mastering Regular Expressions (ISBN 0596002890). And of course, be wary of Dot star! (Death to Dot Star!).

Replies are listed 'Best First'.
Re: Re: Regexp Problem with greedy
by Isanchez (Acolyte) on Sep 11, 2003 at 00:12 UTC
    thank you all for your great advice. Best, Ivo

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://290563]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2022-08-08 06:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found