How to non-greedy multiple lookbehind matches

Posted by ArtK on Stack Overflow See other posts from Stack Overflow or by ArtK
Published on 2009-08-05T09:49:06Z Indexed on 2010/03/27 1:33 UTC
Read the original article Hit count: 327

Filed under:
|
|
Source:    <prefix><content1><suffix1><prefix><content2><suffix2>
Engine:    PCRE

RegEx1:    (?<=<prefix>)(.*)(?=<suffix1>)
RegEx2:    (?<=<prefix>)(.*)(?=<suffix2>)

Result1:   <content1>
Result2:   <content1><suffix1><prefix><content2>

The desired result for RegEx2 is just <content2> but it is obviously greedy. How do I make RegEx2 non-greedy and use only the last matching lookbehind?

[I hope I have translated this correctly from the NoteTab syntax. I don't do much RegEx coding. The <prefix>, <content> & <suffix> terms are just meant to represent arbitrary strings. Only the "<" in the "?<=" lookbehind command is significant.]

I suspect it is something simple but after too many hours of searching I'm giving up on solving it myself.

Thanks for the help

Art

© Stack Overflow or respective owner

Related posts about regex

Related posts about lookbehind