c# - Who can help me write a regular expression? -
i find multi-line text beginning of string cc
kk
end, , must include string c3
, c4
, can not include string dd
or ee
, following test data:
t1 b1 cc c3 c4 z1 t3 dd kk t4 b2 cc c4 c3 z2 t6 ee kk t7 b3 cc c3 c4 z3 t9 ff kk t7 b3 cc c4 c3 z3 t9 ff kk
expected results , only:
cc c3 c4 z3 t9 ff kk cc c4 c3 z3 t9 ff kk
i wrote regular expression(c#), result not expected.
you need make regex engine check condition before matching each single character.
@"(?s)\bcc\b(?:(?!dd|ee).)*?\bkk\b"
(?:(?!dd|ee).)*?
should match character not of dd
or ee
, 0 or more times (non-greedily). \
update:
(?s)\bcc\b(?:(?!\bdd\b|\bee\b).)*?\bc3\b(?:(?!\bdd\b|\bee\b).)*?\bkk\b
Comments
Post a Comment