c# - How to match or list exactly using RegEx -
pattern: ^(?!test|abc).*$
i not want match test or abc only, matches test123
what need add make stop @ end?
you need use end anchor in lookahead well:
^(?!(?:test|abc)$).*$
then, not match test
, abc
whole strings, match test123
.
here regex demo (using pcre engine since work same in .net 1 expression).
to apply $
end-of-string anchor both test
, abc
, need group them, suggest using non-capturing group (or use capturing 1 regexoptions.explicitcapture
).
Comments
Post a Comment