如果我们采用以下模式: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;
}
}
}