Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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!).

In reply to Re: Regexp Problem with greedy by asarih
in thread Regexp Problem with greedy by Isanchez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2024-03-28 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found