I think part of your problem is that you are using square brackets [] inappropriately. They set up a character class so your [.]+ will match one or more literal full-stops; in a character class the full-stop loses it's meta-character meaning of matching any character and becomes a literal. Doing [abc]{3} would match exactly three of either a or b or c.

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


In reply to Re: regex die? by johngg
in thread regex die? by nmerriweather

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.