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

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -