Thanks to all the talented monks you have contributed their wisdom on this problem. I learned a lot from this discussion. I want to explain where/how this problem stemmed from --

As far as I understand, I can use regexp to match certain patterns in text. I can also match text that is NOT a certain pattern.

Now, it seems the look ahead|behind negative|positive give me more power over such matches, however, my toolkit is still very pre-natal in that department.

I want to match certain patterns, but if and only if certain other conditions are met. Here is an example. Suppose I am writing a wiki formatting module.

# I want to match all /italics text/ and replace # it with <i>italics text</i> # except, I don't want to match the text in # [http://somewhere.com/foo/bar.html|Somewhere Else] # in other words, I don't want to end up with # [http:<i></i><i>somwhere.com</i><i>foo</i>bar.html...

The above is just a practical application of the general problem that I was facing. So, to summarize, 'foo' 'bar' 'qux' were general placeholders, as BrowserUk correctly guessed, and to some extent, "surrounded by" 'bar' and 'qux' was interchangeable with surrounded by 'qux' and 'bar'. The more general statement would be --

How to match something, but if and only if, certain other condition is met (or condition is not met, which, actually, is no different from 'condition is met'!).

I need to learn a lot about conditional matching.

--

when small people start casting long shadows, it is time to go to bed

In reply to Re: Match a pattern only if it is not within another pattern by punkish
in thread Match a pattern only if it is not within another pattern by punkish

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.