in reply to Problem parsing an error msg with regex

\w+ doesn't match spaces. Use [^\]]+ instead:
$errmsg =~ /^((?:\[[^\]]+\]){3})(.*)/; or
$errmsg =~ s/^(?:\[[^\]]+\]){3}//;

Update: The directions were correct, but the code was missing a set of parens.

Replies are listed 'Best First'.
Re^2: Problem parsing an error msg with regex
by periapt (Hermit) on Oct 07, 2004 at 14:19 UTC
    Thanks for the idea. I'm afraid your regex didn't work but the problem was, indeed, the spaces. I rewrote the expression as
    $errmsg =~ /^ # start at beginning of string (?: # look at first group \[ # an opening square bracket [\w ]+ # followed by one or more word char/spaces ] # followed by a closing square bracket ) # end first group {3} # capture should be 1 time ( # begin second capture .+ # match anything else 1 or more times ) # close second capture
    and it works as needed. Thanks again

    PJ
    use strict; use warnings; use diagnostics;