in reply to Pattern matching with \t
Your problem is the greedy matching of the (.+) construct. This 'eats up' too much of the whole string. The reason is that you are eating up anything which is not an eol character (see also Death to Dot Star!). As your last part (tab and 2nd number) is completely optional, it is not matched.
The easiest solution - if you are sure that in your normal text ($1) is no tab character - is to write the following:
I also changed your '*' in some cases to '?' which means: match zero or one time, I think this should be the correct multiplicity.$_[0] =~ m/([a-zA-Z0-9\-\_\/\.\,]+) \s*\t ([^\t]+) \t ([0-9\.]+) \t? ([0-9\.]+)?/x; # note the x modifier to allow for # multiline format
If the tab is allowed in the text, you have to use the non-greedy variant of '+' instead:
$_[0] =~ m/([a-zA-Z0-9\-\_\/\.\,]+) \s*\t (.+?) \t ([0-9\.]+) \t? ([0-9\.]+)?/x;
Update: Fixed link.
-- Hofmator
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Pattern matching with \t
by professa (Beadle) on Dec 10, 2001 at 17:55 UTC |