Let's say I have this regex: m/foo(.*?)foo/; What I'm looking to express that I don't know how to is this: how do I make it so that $1 may not contain the substring "bar"? I've looked into ^b^a^r and ^bar both of which are wrong because they either require the string to be at least 3 characters long, don't account for different posiitons of bar within the string, or also disallow "rab" and "arb". So I want to express minimal matching of any arbitrary characters disallowing a certain subpattern. How can I do this? I've heard as a suggestion negative lookahead assertions, but I was under the impression that they were only for matching overlapping pieces of text, i.e. if you were matching: "pop" against "popop" you would use a negative lookahead assertion if you wanted more than one match to be returned. (because the first p of the second "pop" overlaps with the last p of the first match) Any suggestions?

In reply to Regex'ing backreferences by Uruk

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.