我有加拿大邮政编码的正则表达式.
^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$
Run Code Online (Sandbox Code Playgroud)
它工作正常,但只接受大写字母.我希望它适用于大写和小写字母.
我已经搜索了这样的问题,但是我发现的所有情况都是以特定于问题的方式解决的,例如在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),但不能弄明白.这甚至可能吗?
我在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中它确实匹配.
如果我们采取以下模式: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) 如果值与某个条件匹配,则检查该值.值如下所示:
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#的新手.