Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Match some lines
- one man army
May 7, 2005, 12:04 pm
rate this thread
Hi All You Perl Folk-
I am new to regular expressions. I am reading a manual. I have a
problem I am not figuring out. Perhaps you have some insights.
Since regular expressions are 'greedy', I am having a problem removing
data blocks out of a long, machine generated text file.
I got as far as making the file look like:
(about 70 lines of text, not always exactly 70)
(about 411 lines of text, not always exactly 411)
that continues about 230 times.
SO I want to write something that saves the 70 lines, and gets rid of
the 411. But since RegExp are greedy, my simple attempt matches
basically the whole file.
What do you do with that?
email as well as post, if you please
(news AT s c r e e n l i g h t DOT c o m)
thanks in advance!
Re: Match some lines
one man army wrote:
> Since regular expressions are 'greedy', I am having a problem
Then just make the match non-greedy.
From "perldoc perlre":
By default, a quantified subpattern is "greedy", that is, it will match
as many times as possible (given a particular starting location) while
still allowing the rest of the pattern to match. If you want it to match
the minimum number of times possible, follow the quantifier with a "?".
Note that the meanings don't change, just the "greediness".
- » Please help me return multiple valus from a subroutine
- — Previous thread in » PERL Discussions