For instance..
Sample Text: <tag>AandBandCandD</tag>
I need to match everything that occurs between tag> and </tag excluding any instances of "and" so the result is:
"ABCD"
For instance..
Sample Text: <tag>AandBandCandD</tag>
I need to match everything that occurs between tag> and </tag excluding any instances of "and" so the result is:
"ABCD"
I'd do this in two steps:
and with the empty string.Regular expressions are not the right tool for either step:
Update
If you are forced to use a single regular expression, then it's probably not possible.
This is something you can try, anyway.
(?<=<tag>)(?:((?!and).)+(?:and)?)*(?=</tag>)
Broken down for readability:
(?<=
<tag>
)
(?:
(
(?!
and
)
.
)+
(?:and)?
)*
(?=
</tag>
)
I'm pretty sure this would produce a number of matches equal to the text between the ands. But without knowing the exact regex language in question, there's a ton of things that could break this by being just a little different.