开发者

Regex not equal to string

I'm banging my head against a wall with a regular expression. I'm trying to define an expression that excludes exactly this text 'System' (case insensitive), but can contain the word 'System' providing it's no开发者_如何学Got just that.

Examples:

  • System == INVALID
  • SYSTEM == INVALID
  • system == INVALID
  • syStEm == INVALID
  • asd SysTem == Valid
  • asd System asd == Valid
  • System asd == Valid
  • asd System == Valid
  • asd == Valid


Try this:

^(?!system$)

Or this to match the whole line:

^(?!system$).*$

The regex has a negative look-ahead on its beginning, which doesn't match if "system" is the entire string.


Reject if it matches ^system$ (make sure i flag is ON).


^$|^.{1-5}$|.{7}|^[^s]|^.[^y]|^..[^s]|^...[^t]|[^e].$|[^m]$ 

But use amarghosh's answer if you can.

(updated as per suggestion below)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜