I have been doing perl for quite some time now, and have been able to write some pretty advanced regular expressions, but now a relatively simple(I hope) problem has me stumped. Many times while running testcases we diff gold file with the results file generated. Now the result file generated(and the gold file) The files have lines which contain
file /user/name/some/path/to/filename@@ dumped: replaced /user/name/bl +ah/blah/filename Sometimes we have this @@@@user/some/file/filename.sdc: dumped
Now obviously this will fail whenever the run path changes. So I was trying this s:/.*/\(\w\+\)/\1/g equivalent and kinds etc., but if you have 2 paths dumped on the same line, it will eat up text in between that too because of greedy nature. What I really want is a bullet proof regexp which will change every instance of /home/user/blah/blah...../filename to filename This seems so simple yet so difficult because sometimes the filename is followed by whitespace, sometimes by @ sometimes by : or sometimes by any other special character(but never a word of a number)

In reply to This regular expression has me stumped by tsk1979

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.