正则表达式来检查,如果一个字不存在 [英] Regex to check if a word doesn't exist
本文介绍了正则表达式来检查,如果一个字不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的测试字符串中包含新行。
测试<试验。
sdasdsadads
测试<试验。测试<试验。
我要检查,如果组合<
在文本中的任何地方存在。如果是这样,我正则表达式应该失败。
任何想法?
ASP.NET网页。\\
< TD>
< ASP:文本框ID =测试=服务器HEIGHT =55像素的TextMode =多行>< / ASP:文本框>
< ASP:RegularEx pressionValidator ID =RegularEx pressionValidator11=服务器
的ControlToValidate =测试显示=动态前景色=红
的ValidationGroup =验证ValidationEx pression =^(?![\\ S \\ S] *< \\?)EnableClientScript =真>< / ASP:RegularEx pressionValidator>
< / TD>
解决方案
喜欢这个?
!Regex.IsMatch(的TestString,Regex.Escape(<?))
或者更简单:
!testString.Contains(<?)
仅使用正则表达式(这会为新行的工作也):
^([\\ S \\ S] *<!\\?)
My test string is contains New Lines.
Test<?TEST.
sdasdsadads
Test<?TEST.
Test<?TEST.
I want to check if the combination <?
exists anywhere in the text. If so, my regex should fail.
Any ideas?
ASP.NET web page.\
<td>
<asp:TextBox ID="test" runat="server" Height="55px" TextMode="MultiLine"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator11" runat="server"
ControlToValidate="test" Display="Dynamic" ForeColor="Red"
ValidationGroup="Validations" ValidationExpression="^(?![\s\S]*<\?)" EnableClientScript="true"></asp:RegularExpressionValidator>
</td>
解决方案
Like this?
!Regex.IsMatch(testString, Regex.Escape("<?"))
Or even easier:
!testString.Contains("<?")
Using only a regex (this will work for newlines also):
^(?![\s\S]*<\?)
这篇关于正则表达式来检查,如果一个字不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文