in reply to regex die?
It also makes things easier when matching paths to choose a delimiter character other than "/" by using the m operator. You can choose a character like the pipe symbol "|" or balanced brackets like {}. Once you've done that you no longer have to escape the "/" characters.
My (non-tested) attempt at your sub die_clean would be:-
sub die_clean { my $input = shift; my ($msg, $line) = $input =~ m{(.+?)( at /\S+ line \d+\.$}; }
The $ sign anchors the match to the end of the string just on the off-chance that the "MY ERROR" part contains "at /pathe/to/file line n." which is unlikely but stranger things have happened. The .+? says match one or more of any character in a non-greedy fashion. You want to do this otherwise a .+ without the ? would consume the entire string and not leave any characters for the rest of the regular expression to match.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex die?
by ayrnieu (Beadle) on Mar 19, 2006 at 22:31 UTC | |
by johngg (Canon) on Mar 19, 2006 at 23:51 UTC | |
by GrandFather (Saint) on Mar 19, 2006 at 23:58 UTC | |
by ayrnieu (Beadle) on Mar 19, 2006 at 23:57 UTC | |
by johngg (Canon) on Mar 20, 2006 at 09:38 UTC |