正则表达式 - 不包含某些字符 [英] Regex - Does not contain certain Characters

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

问题描述

我需要一个正则表达式来匹配,如果句子中的任何地方都没有 <或 >.

I need a regex to match if anywhere in a sentence there is NOT either < or >.

如果任一<或 > 在字符串中,那么它必须返回 false.

If either < or > are in the string then it must return false.

我在这方面取得了部分成功,但前提是我的 <> 在开头或结尾:

I had a partial success with this but only if my < > are at the beginning or end:

(?!<|>).*$

我正在使用 .Net,如果这有区别的话.

I am using .Net if that makes a difference.

感谢您的帮助.

推荐答案

^[^<>]+$

字符类中的插入符号 ([^) 表示匹配任何内容,因此这意味着,字符串的开头,然后是除 <>,然后是字符串的结尾.

The caret in the character class ([^) means match anything but, so this means, beginning of string, then one or more of anything except < and >, then the end of the string.

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

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