in reply to Extracting string from a file
As it stands, I don't think your code even compiles, since you've got an unbalanced '(' in your regular expression. I'd start by fixing that.
Mike
Second, '|' is a special character in regular expressions, meaning "this OR that". Since you want a literal '|', you need to precede it with a '\'.
Next, you're using '|' again between TOTAL and your digits, while your example has spaces there. Which is it?
'\d' is a character class by itself - it doesn't go in square brackets. But since you also need to match '.', use '0-9.'. Do you also need to match negative numbers? If so, that would be '-0-9.'.
Finally, you're only capturing the first number, and you said you need both.
Putting all of that together, please try this regular expression:
I think that might work better for you..../\|TOTAL\s+([0-9.]+)%\s+([0-9.]+)/
Test case:
perl -e'$_="~|TOTAL 24.1% 0.4%"; /\|TOTAL\s+([0-9.]+)%\s+([0-9.]+)/ && + print "Matched, $1 $2\n"' Matched, 24.1 0.4
Mike
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Extracting string from a file
by ww (Archbishop) on Nov 11, 2013 at 13:50 UTC | |
by Bindo (Acolyte) on Nov 18, 2013 at 10:26 UTC | |
by Bindo (Acolyte) on Nov 20, 2013 at 05:15 UTC | |
by ww (Archbishop) on Nov 20, 2013 at 13:18 UTC | |
Re^2: Extracting string from a file
by oiskuu (Hermit) on Nov 12, 2013 at 03:19 UTC | |
Re^2: Extracting string from a file
by Bindo (Acolyte) on Nov 20, 2013 at 05:13 UTC |
In Section
Seekers of Perl Wisdom