gpt4 book ai didi

javascript - 正则表达式:匹配帐号,但不匹配 token /生日

转载 作者:行者123 更新时间:2023-12-03 04:25:09 26 4
gpt4 key购买 nike

我正在努力解决以下正则表达式:

\b[\dBb][-. \dEe]+(\d{4})\b

它应该匹配帐号,但不匹配 token /生日或其中包含“be”的文本。在 community 的支持下,我成功捕获了第一部分。但是,我似乎无法排除 token /生日。

应该匹配的大小写(我的正则表达式工作正常):

1234 1234 1234 1234
1234 1234 1234 1234 1
BE12 1234 1234 1234
1234-1234-1234-1234
1234.1234.1234.1234
1234123412341234
12341234 1234 1234
1234-1234-1234-1234-1
1234.1234.1234.1234.1
12341234123412341
12341 234 1234 12341
BE12-1234-1234-1234
be12-1234-1234 1234
Be12.1234.1234-1234
BE12123412341234

不应匹配的情况(我的正则表达式对于其中一些情况无法正常工作):

123456
Token: 123456
I shall be awesome in Belgium, as my birthdate is 01/01/2000.
01.01.2000
01012000
first of january 2000

你能帮助解决这个挑战吗?谢谢!

最佳答案

匹配 BE 或 2 位数字,后跟 14 或 15 位数字,其中散布着空格、句点和破折号

([Bb][Ee]|\d\d)([-. ]?\d){14,15}

测试:

ACCOUNT             INPUT
1234123412341234 1234 1234 1234 1234
12341234123412341 1234 1234 1234 1234 1
BE12123412341234 BE12 1234 1234 1234
1234123412341234 1234-1234-1234-1234
1234123412341234 1234.1234.1234.1234
1234123412341234 1234123412341234
1234123412341234 12341234 1234 1234
12341234123412341 1234-1234-1234-1234-1
12341234123412341 1234.1234.1234.1234.1
12341234123412341 12341234123412341
12341234123412341 12341 234 1234 12341
BE12123412341234 BE12-1234-1234-1234
be12123412341234 be12-1234-1234 1234
Be12123412341234 Be12.1234.1234-1234
BE12123412341234 BE12123412341234
No Match 123456
No Match Token: 123456
No Match I shall be awesome in Belgium, as my birthdate is 01/01/2000.
No Match 01.01.2000
No Match 01012000
No Match first of january 2000
Be12123412341234 Here is my account number Be12.1234.1234-1234. have a nice day

验证器(Ruby):

a = [ "1234 1234 1234 1234",
...
]

puts 'ACCOUNT INPUT'
a.each { |s|
match = /(([Bb][Ee]|\d\d)([-. ]?\d){14,15})/ =~ s
puts "%-18s %s"%[ match ? $1.tr('-. ', '') : "No Match", s ]
}

关于javascript - 正则表达式:匹配帐号,但不匹配 token /生日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43767312/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com