正则表达式 - 如何排除单个单词? [英] Regex - how to exclude single word?

查看:60
本文介绍了正则表达式 - 如何排除单个单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ 用于验证.验证规则的定义方式如下:

I am using http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ for validation. Validation rules are defined in a following way:

            "onlyLetterSp": {
                "regex": /^[a-zA-Z\ \']+$/,
                "alertText": "* Only letters"
            }

我想添加新规则,它将排除一个单词.我在 StackOverflow 上阅读了一些类似的问题,并试图用这样的东西来声明它

I would like to add new rule, which will exclude one single word. I have read some similar questions on StackOverflow and tried to declare it with something like this

"regex": /(?!exclude_word)\^[a-zA-Z\ \']+$/,

但是没有用.你能给我一些建议吗?

But it didn't work. Can you give me some advices how to do it?

推荐答案

\b(?:(?!word)\w)+\b

不会匹配单词".

这篇关于正则表达式 - 如何排除单个单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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