Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: Regex conditional match if previous match in same expression is true?

by radiantmatrix (Parson)
on Apr 10, 2007 at 15:55 UTC ( [id://609184]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Regex conditional match if previous match in same expression is true?
in thread Regex conditional match if previous match in same expression is true?

Thank you! That was deeply instructive -- where I work I code primarily in a vacuum (well, there is one other Perl user, but he's just now learning), so it's nice to see the thought process of a more experienced Monk.

Just out of curiosity, I note that you used the Perl-only capability of executing Perl code inside a conditional. Despite being *way* off topic, I am interested to know if that's really the only sensible way to do this (that is, accomplish my goal using a conditional rather than an alternation). For example, if I were to use Jakarta-ORO (Perl-style regex engine for Java), I suspect I wouldn't have that facility.

Feel free to /msg me if you don't want to carry this OT discussion in-thread, we could pick it up in e-mail. Or, if you prefer, could you recommend a chapter of Mastering Regular Expressions that covers the topic well? I've bought the book, but haven't yet had the time to read it start-to-finish.

<radiant.matrix>
Ramblings and references
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet
  • Comment on Re^4: Regex conditional match if previous match in same expression is true?

Replies are listed 'Best First'.
Re^5: Regex conditional match if previous match in same expression is true?
by ikegami (Patriarch) on Apr 10, 2007 at 16:23 UTC

    Rhandom provided a better solution. Here's a simplification of it:

    / (?: ({) | (?<!{) ) hello (?(1) } | (?!}) ) /x

    It doesn't "use Perl", but I suspect it won't solve your compatibility problems like you think it will. Are you sure that engine supports conditionals ((?(...)...|...))?

    I've never read "Mastering Regular Expressions".

      Yes, the Jakarta-ORO provides a Perl5Matcher class (and relatives) that supports all of the Perl-5 regex engine, with the (fairly obvious) exception of being able to execute Perl inside a regex.

      It's been a lifesaver on one of my current projects, where I have to use Java (plugins for a J2EE app, plus boss requirement) to do tasks particularly suited to regexen. I'm thankful to the Jakarta folks for making it so that I don't have to learn Yet Another Regex Syntax. ;-)

      <radiant.matrix>
      Ramblings and references
      The Code that can be seen is not the true Code
      I haven't found a problem yet that can't be solved by a well-placed trebuchet

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-20 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found