Make sure the regex subpattern doesn't contain the previous subpattern?
I am wondering if there is a way to check if the subpattern matches a given sequence so that I can block it.
For example, let's say that I wanted to capture everything except a repeat of an earlier capture. So if I had a suggestion [word plus word]
, the next would have to log everything ( word plus
) up to the second occurrence word
.
(\w+)[^\1]+
The first is (\w+)
exciting word
. The second capture group [^...]
tries to exclude it (it was previously marked \1
), but it only works on characters, not subpanel captures.
Is there anyway to do this?
source to share