Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^3: How should I Extract data from text file. Pattern I have to extract should not repeated one.by roboticus (Chancellor) |
on Feb 04, 2018 at 14:43 UTC ( [id://1208424]=note: print w/replies, xml ) | Need Help?? |
Well, while you have several lines that match the pattern ([N01]{39}), none of the lines stop after the last [N01] match, they all have a semicolon and more text after them. Try changing the line to not require that the line end immediately after that, like this:
or alternatively, specify that the string should be followed with a semicolon:
It would be helpful if you'd re-read perldoc perlre and verify that your expressions are saying what you really mean. When I have a problem with a pattern, I usually do something akin to putting this at the start of the file:
And then run the file as a perl script. Then you can tweak your regex until you get what you're looking for. For example, when I ran it with the above bit of code on the front, I got this:
I then removed the '$' from your condition, re-ran it and got:
Update: Fixed wording and formatting (code tags so square brackets don't linkify) in first sentence. ...roboticus When your only tool is a hammer, all problems look like your thumb.
In Section
Seekers of Perl Wisdom
|
|