.NET Regex整个字符串匹配

Wjd*_*is5 3 .net c# regex sqlclr

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

    }
Run Code Online (Sandbox Code Playgroud)

小智 6

尝试使用

^$ 
Run Code Online (Sandbox Code Playgroud)

正则表达式中的运算符强制开始和结束匹配.