如果我们采用以下模式: 70000@.* 和 970000@.* 字符串 970000@ILoveFishSticksAndTarTarSauce.com:5060 将返回匹配 70000@.*
我理解它为什么匹配,但我需要修改正则表达式以只进行完整的字符串匹配。
有任何想法吗?
谢谢!
我正在使用 .Net 3.5 库
这是代码:
[Microsoft.SqlServer.Server.SqlProcedure]
public static void RouteRegex(string phoneNumber, out string value)
{
if (string.IsNullOrEmpty(phoneNumber))
{
value = string.Empty;
return;
}
const string strCommand =
"Select RouteID,sequence,Pattern From SIPProxyConfiguration.dbo.Routes order by routeid, sequence asc";
using (var connection = new SqlConnection("context connection=true"))
{
try
{
connection.Open();
using (var command =new SqlCommand(strCommand,connection))
{
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
var regEx = reader[2] as string;
if (string.IsNullOrEmpty(regEx)) continue;
var routeId = reader[0];
var sequence = reader[1];
var match = Regex.Match(phoneNumber, regEx);
Regex.IsMatch()
if (!match.Success) continue;
value = routeId.ToString();
return;
}
}
}
value = "No Match!";
}
catch (Exception ex)
{
value = ex.Message;
return;
}
}
}