相关疑难解决方法(0)

如何使正则表达式匹配不区分大小写?

我有加拿大邮政编码的正则表达式.

^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$
Run Code Online (Sandbox Code Playgroud)

它工作正常,但只接受大写字母.我希望它适用于大写和小写字母.

.net c# regex

27
推荐指数
1
解决办法
4万
查看次数

正则表达式只有在缺少给定的子字符串/后缀时匹配整个字符串

我已经搜索了这样的问题,但是我发现的所有情况都是以特定于问题的方式解决的,例如在vi中使用!g来否定正则表达式匹配,或匹配其他内容,而不使用正则表达式否定.

因此,我对这个"纯粹"的解决方案感兴趣:

有一组字符串我需要使用正则表达式匹配器过滤它们,以便它只留下(匹配)缺少给定子字符串的字符串.例如,过滤掉"Foo":

Boo
Foo
Bar
FooBar
BooFooBar
Baz
Run Code Online (Sandbox Code Playgroud)

会导致:

Boo
Bar
Baz
Run Code Online (Sandbox Code Playgroud)

我试图用消极构建它的外观aheads /屁股(?!regex)/ (?<!regex),但不能弄明白.这甚至可能吗?

regex regex-negation

8
推荐指数
1
解决办法
7146
查看次数

Regex Go不匹配

我在regexr中开发了一些正则表达式,它按预期工作,但是当我在Go中使用它时,似乎是不匹配的字符串.

(\+|-)?(((\d{1,3}[, ])(\d{3}[ ,])*\d{3})|\d+)( ?[\.,] ?(\d{3}[, ])*\d+)?
Run Code Online (Sandbox Code Playgroud)

例如,在regexr中,以下输入不匹配:

1.12,4.64
Run Code Online (Sandbox Code Playgroud)

但在Go中它确实匹配.

regex go

5
推荐指数
1
解决办法
106
查看次数

.NET Regex整个字符串匹配

如果我们采取以下模式: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]; …
Run Code Online (Sandbox Code Playgroud)

.net c# regex sqlclr

3
推荐指数
1
解决办法
4445
查看次数

Regex.IsMatch无效

如果值与某个条件匹配,则检查该值.值如下所示:

123456:123abc89是:0099 @ ABC123

这是我的C#程序分析值的方式:

if (Regex.IsMatch(input, "[0-9]:[a-zA-Z0-9]:[a-zA-Z0-9]@[a-zA-Z0-9]") == true)
{
    Console.WriteLine("Correct.");
}
Run Code Online (Sandbox Code Playgroud)

出于某种原因,它不起作用.你有什么想法?请记住,我是C#的新手.

c# regex

-5
推荐指数
1
解决办法
2366
查看次数

标签 统计

regex ×5

c# ×3

.net ×2

go ×1

regex-negation ×1

sqlclr ×1