Greedy Regex Matching
I'm trying to match a string that looks something like this:
<开发者_运维百科;$Fexample text in here>>
with this expression:
<\$F(.+?)>{2}
However, there are some cases where my backreferenced content includes a ">", thus something like this:
<$Fexample text in here <em>>>
only matches example text in here <em
in the backreference. What do I need to do to conditionally return a correct backrefernce with or without these html entities?
You can add start and end anchors to the regex as:
^<\$F(.+?)>{2}$
Try
<\$F(.+?)>>(?!>)
The (?!>)
forces only the last >>
in a long sequence of >>>..>>>
will be matched.
Edit:
<\$F(.+?>*)>>
Also works.
Please note than tu truly do what (I think) you want to do, you would have to interpret well-formed bracket expressions, which is not possible in a regular language.
In other words, <$Fexample <tag <tag <tag>>> example>> oh this should not happen>
will return example <tag <tag <tag>>> example>> oh this should not happen
as the capture group.
精彩评论