Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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:
  • "foo 1000 bar 1000"
  • "foo 1000 bar 500"

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-18 23:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found