in reply to Problem parsing an error msg with regex

Try this:

$errmsg =~ /^((?:\[.+?\]){3})(.*)/;

The first three brackets are in $1 and the rest of the string in $2.
If all you want is the last part (after the 3 brackets) just do:

$errmsg =~ /^(?:\[.+?\]){3}(.*)/;

As a quick breakdown (of the first version, the same is the second but without the brackets around (?:\[.+?\]){3}).

$errmsg =~ /^ # Start of string ( # Start match $1 (?: # Start group (don't save backreference) \[.+?\] # Match set of []'s ){3} # End group and repeat 3 times ) # End match $1 (.*) # Slurp up everything that's left /x; # Done

--- Jay

All code is untested unless otherwise stated.

Replies are listed 'Best First'.
Re^2: Problem parsing an error msg with regex
by periapt (Hermit) on Oct 07, 2004 at 14:24 UTC
    Great, thanks. This one works in a more general sense since I was restricting the stuff between the brackets a bit.

    PJ
    use strict; use warnings; use diagnostics;