regex - How to find all occurrences of a word when not preceded by another? -
how find occurrences of word when not preceded another? example, want able find instances of 'sugar' not 'blood sugar'.
in following:
increase in sugar cause increase in blood sugar , more sugar consumed ...
the above should make 2 matches , not 3
many in advance
if regex language supports negative behinds, can use (?<!blood )sugar
handle case without case sensitive issues. depending on language, can add flag regex provide case insensitivity. allow find cases of condition using weird combination of upper , lower case letters. used example testing here.
the regex simple, negative behind (?<!blood )
of string looking sugar
. match string if not preceded blood
. space not need returned match, included part of behind, instead of before suguar
.
Comments
Post a Comment