in reply to regular expressions. help
First of all, is that assignment to $evalme on purpose? Are you in fact evaling the variable after this?
Second, you don't need the s/^ //; line. What it does is remove a single space from the beginning of the line. But if you want to ignore one leading space, you may as well ignore any leading whitespace:
if (/^\s*HISTOGRAM ...rest of re.../)
In fact, it may (or may not, depending on how well-formed your data is) be reasonable to just drop the ^ anchor.
Finally, for the reason why this regexp fails. You have "OF(\w+)$", which reads "the word characters that continuously occupy from immediately after the letters "OF" to the end of the line". This must fail because you have non-word characters in the rest of your line, indeed you have a space *immediately* after "OF"!
I couldn't understand if you're looking for the word that comes between the next two asterixes ("gpa" in this example) or if the next text inside parentheses (" 226" in this example) is what you want to capture. If the former, the following should work. I'm using extended regexp syntax for added readability:
m{ HISTOGRAM \s+ OF \s+ \* \s* # a literal "*", escaped because * is a metacharacter ([^*]+?) # (capture) anything that isn't a "*", nongreedy \s* \* }x;
The group "(^*+?)" is "nongreedy", which means that (since it is followed by \s*, whitespace) it will automatically not include any trailing whitespace between the word and the following asterix.
|
|---|