正则表达式不等于字符串 [英] Regex not equal to string

查看:2533
本文介绍了正则表达式不等于字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敲我的头靠在墙上一个普通的EX pression。我试图定义一个EX pression排除正是本文'系统'(不区分大小写),但可以包含 这个词系统提供它不只是这一点。

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 not just that.

例如:

  • 系统==无效
  • 系统==无效
  • 在系统==无效
  • 在系统==无效
  • 在ASD系统==有效
  • 在ASD系统ASD ==有效
  • 系统ASD ==有效
  • 在ASD系统==有效
  • 在ASD ==有效

推荐答案

试试这个:

^(?!system$)

或者这个匹配整个行:

^(?!system$).*$

正则表达式在其开始时,不匹配,如果系统是整个字符串的负先行

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

这篇关于正则表达式不等于字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆