次のパターンを取る場合:70000@。*および970000@。*文字列970000@ILoveFishSticksAndTarTarSauce.com:5060は70000@。*に一致を返します。
一致する理由は理解できますが、完全な文字列一致のみを行うように正規表現を変更する必要があります。
何か案は?
ありがとう!
.Net3.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;
}
}
}