The basic problem stems from a too-liberal use of the  (?:\b|_) assertion.

The  $parse1 string begins with a  / (forward slash) character. This is not a \w character. The  (?:\b|_) assertions in  (?:\b|_)$parse1(?:\b|_) require that  $parse1 be preceded by a \w character or a  _ (underscore) (note that  _ is a member of the \w class), and followed by a non-\w character or a  _ (underscore).

What the OPed regex will match depends on the string it is matching against. I would advise giving us examples of typical strings. Below are some examples of mine that show various matches/non-matches:

c:\@Work\Perl>perl -wMstrict -le "print qq{perl version: $] \n}; ;; my $parse1 = '/newsearch/detail/96603'; my $parse2 = ''; ;; for ( qq{xxx \n/newsearch/detail/96603\n xxx}, qq{xxx \n/newsearch/detail/96603x\n xxx}, qq{xxx \nx/newsearch/detail/96603x\n xxx}, qq{xxx \nx/newsearch/detail/96603\n xxx}, qq{bla vla/newsearch/detail/96603 x}, ) { print qq{<<$_>>}; print qq{MATCH '$&'} if /^.*?(?:\b|_)$parse1(?:\b|_).*?(?:\b|_)$parse2(?:\b|_).*?$/m; print ''; } " perl version: 5.008009 <<xxx /newsearch/detail/96603 xxx>> <<xxx /newsearch/detail/96603x xxx>> <<xxx x/newsearch/detail/96603x xxx>> <<xxx x/newsearch/detail/96603 xxx>> MATCH 'x/newsearch/detail/96603' <<bla vla/newsearch/detail/96603 x>> MATCH 'bla vla/newsearch/detail/96603 x'

Update: Because you give no examples of the typical strings you're matching against, I cannot understand the implications of the  ^.*? and  .*?$ and  .*?(?:\b|_)$parse2(?:\b|_) portions of the OPed regex (which I suspect may be superfluous), or why you are matching in  /m "multi-line" mode.


Give a man a fish:  <%-{-{-{-<


In reply to Re: seeking expression to match "/mysearch/detail/966031" by AnomalousMonk
in thread seeking expression to match "/mysearch/detail/966031" by Anonymous Monk

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.