开发者

RegEx help - find substring except when in specific word(s)

A colleague is scanning a large script looking for the substring UAT (case insensitive). Unfortunately, the script co开发者_运维问答ntains many references to "valuation", either as a whole word or as part of a field name.

What RegEx search pattern would return matches for UAT as in the following samples?

  • UAT : Match
  • uat : Match
  • TheUATServer1 : Match
  • Valuation : No match
  • ValuationDate: No match

Many thanks

Neil


Edit: This one works for the OP's cases.

Try this expression: uat~(ion)

The SSMS (and Visual Studio) regex has different syntax for negative lookahead: ~(prevent)

If you wanted uat by itself, you can use this: <uat>.

The < and > stand for begining and end of word, respectively.


fgrep -i "uat" FILE | fgrep -i -v "valuation"

Sometimes the simplest tools can do amazing things.

But you did not specify the tools you have, the regex flavor (there are many). And what you are searching for can be defined via regex (negative look-(ahead|behind)), but simple string search and negation can be faster.


You can try this

UAT(?!ion)

This is a negative lookahead, that ensures that UAT is not followed by ion like in valuation. I don't know if your tool is supporting this and if this rule is strict enough for your needs.

What you should activate is a case insensitive match.


EDITED to be case insensitive and incorporate new requirement

I think the regex you want is simply:

[Uu][aA][tT](?![iI][oO][nN])

ie uat (any case) not followed by ion (any case)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜