Help me obi-several, you're my only hope.

I'm not confident I phrased that right in the title. But here 'goes. (I know this is out there but I don't have any hooks on what to call it to search.)

I have 2 strings:

and I'm starting with something like:

/foo (\d+) bar (???)/

My goal is to match the first string but not the second. I couldn't care less what the values are, merely whether or not they are equal.

I seem to recall it being possible (and perhaps fundamental) to match against "the string that matched grouping N".

But for the life of me I can't figure out how to do it, or what kind of keywords to search for to dig this up.

(please feel invited to edit this for clarity.)

UPDATE: Damnit. My fault. There's an additional restriction. The regex itself is to be included in a fairly obtuse dispatch mechanism so the test needs to be constrained entirely to the matching of the expression. (does that make sense?)

Here's another wrinkle for the willing: Given that I can match easily enough with backrefs those two numbers, anyone know how to, again entirely within the scope of the regex match, return a POSITIVE match if the two numbers (both of \d+ format) do NOT match? (Yes, this is a practical independent real-world case. Ah, the joys of parsing log files in realtime.)

Thanks very much for your help (this article pushes me up to Monk! *SQUEE*)

-V

In reply to regex search valid only if registers n and n+1 are equal? by Voronich

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.