Html 正则表达式不';I don’我找不到一个匹配的模式
在一个C#项目中,正则表达式对我来说表现得很奇怪 我有这个方法:Html 正则表达式不';I don’我找不到一个匹配的模式,html,.net,regex,Html,.net,Regex,在一个C#项目中,正则表达式对我来说表现得很奇怪 我有这个方法: string RegTest() { string HTML = "<input type=\"hidden\" name=\"authenticity_token\" value=\"d27956cca6b75db4d8dd502d0569dd246455131c\">"; Regex AuthRegex = new Regex(@"name=""authenticity_to
string RegTest()
{
string HTML = "<input type=\"hidden\" name=\"authenticity_token\" value=\"d27956cca6b75db4d8dd502d0569dd246455131c\">";
Regex AuthRegex = new Regex(@"name=""authenticity_token"" value=""([A-Ba-b0-9/-]+)""");
string Auth = AuthRegex.Match(HTML).Value;
return Auth;
}
string RegTest()
{
字符串HTML=“”;
Regex AuthRegex=new Regex(@“name=”“authenticity_token”“value=”“([A-Ba-b0-9/-]+)”);
字符串Auth=AuthRegex.Match(HTML).Value;
返回Auth;
}
出于一个我完全不理解的原因,正则表达式找不到与此模式匹配的任何东西。它只返回”
如何解决此问题?问题是:
[A-Ba-b0-9/-]+
字符范围(x-y
)的基本功能是获取一组介于两者之间的所有字符。换句话说,a-b
=介于a
和b
之间的所有字母,也就是仅a
和b
。但是,
d27956cca6b75db4d8dd502d0569dd246455131c
看起来像个妖术。因此,您应该使用
[A-Fa-f0-9-]+
相反。@ndn我认为通过使用
@
我不需要逃避它。什么是正确的方式来摆脱它的模式?好的,非常感谢!现在我也注意到我写了A-B
,而不是像平时那样写A-Z
-_-