Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Regex problems using '|'

by moritz (Cardinal)
on Jul 22, 2008 at 09:45 UTC ( [id://699244]=note: print w/replies, xml ) Need Help??


in reply to Regex problems using '|'

Show us some example data, and what you want to extract from it. Please also include example data that should not match (if there is data like that in your application).

Replies are listed 'Best First'.
Re^2: Regex problems using '|'
by romandas (Pilgrim) on Jul 22, 2008 at 10:34 UTC
    Okay, I posted some. What I don't understand is if I just use /Remediation Report\n\n(.+?)\n/, I get the line I'm looking for (Adobe Flash Player Multiple Vulnerabilities - April 2008 - IE), but if I use /Remediation Report\n\n(.+?)\n|^(.+?)\n/, I get the top of the metadata (thread-index: AcjoCau17Ri90HMJR8qoukn2A1g7ng==).
      The regex engine starts at the start of the string, and tries to match the first alternative, here Remediation Report\n\n(.+?)\n. It doesn't match, so it tries the second alternative, ^(.+?)\n. That one matches, so it captures the first line in $1.

      Without the alternation, the regex engine moves its starting position until it finds the substring Remediation Report.

      (Actually it's much smarter than that; it searches for the constant substring with the same techniques that index uses, but from a users point of view that only matters when it comes to speed, not in terms of functionality).

        I'm not sure why the match is failing with the alternation when it matches correctly without it. I understand that if the first pattern does not match, it will go on to the second half . That's the behavior I want with regards to the rest of the records. Why is the match failing? That's what I do not understand, since it works correctly as long as the alternation is removed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://699244]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-12-02 17:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found