如何匹配任何由大写字母组成的字符串,有时将其与数字混合,且至少包含4个字符,而没有最大字符。但是我也想避免匹配年份(任何以1开头的4位数字),例如1912、1830、1998,因为它们不是字母/数字混合字符串的一部分。
带有字符串以粗体匹配的示例文本:
Lorem ipsum消费者11NFJVC胡萝卜FXUT0番茄1976STK adipisc XWWFHH年1912。
如果我对您的理解正确,那么这很合适:
(?<![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
看到它住在regex101.com。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句