好吧,这真的很奇怪。我有以下简单的regex搜索模式奇怪的正则表达式(正则表达式)匹配!不匹配数字
\d*
遗憾的是它不
*-7d
匹配 “7” 但是当我测试了以下的正则表达式搜索模式
xx
它匹配器“xx”in
asdxxasd
完全奇怪! 顺便说一句,我使用正常的C#正则表达式对象。 虽然预先感谢任何帮助!
对不起,我的代码如下:
public static string FindFirstRegex(string input,string pattern)
{
try
{
Regex _regex = new Regex(@pattern);
Match match = _regex.Match(input.ToLower());
if (match.Success)
{
return match.Groups[0].Value;
}
else
{
return null;
}
}
catch
{
return "";
}
}
我所说的功能如下:
MessageBox.Show(utilities.FindFirstRegex("asdxxasd", "xx"));
MessageBox.Show(utilities.FindFirstRegex("ss327d", "\\d*"));
请张贴演示问题的一些代码。 –
借调奥利查尔斯沃思,但是你可能忘记在C#正则表达式字符串中逃避你的反斜杠? –