如何匹配任何由大写字母组成的字符串,有时与数字混合, 至少4个字符,没有最大值。但我也想避免匹配年份(任何以1开头的4位数字),例如1912年,1830年,1998年,当时它们不是混合字母/数字字符串的一部分。
包含要以粗体显示的字符串的示例文本:
Lorem ipsum dolor 11NFJVC 坐下来 FXUT0 consectetur 1976STK adipisc XWWFHH 1912年。
答案 0 :(得分:2)
答案 1 :(得分:1)
如果我理解正确,这符合法案:
(?<![A-Z\d])(?!1\d{3}\b)[A-Z\d]{4,}(?![A-Z\d])
<强>说明:强>
(?<![A-Z\d]) # Make sure the previous character isn't uppercase alphanumeric
(?! # Assert that it's impossible to match...
1 # the digit 1
\d{3} # followed by three more digits
(?![A-Z\d]) # where no other uppercase alphanumerics follow.
) # (End of lookahead)
[A-Z\d]{4,} # Match 4+ alphanumeric characters (uppercase letters only)
(?![A-Z\d]) # Make sure the next character isn't uppercase alphanumeric
答案 2 :(得分:0)
像
这样的东西\b(?!\d+\b)[A-Z\d]{4,}\b