我只需要从一个只有数字和字母组合存在的句子中检测单词。
我正在使用这个https://regex101.com/r/eSlu2I/1 ^[a-zA-Z0-9]*正则表达式。
在这里,最后两个应该被排除在外。有人能帮我吗?
发布于 2022-05-16 21:14:25
使用
^(?![a-zA-Z]+\b)[a-zA-Z0-9]*见正则证明。
解释
NODE EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
[a-zA-Z]+ any character of: 'a' to 'z', 'A' to 'Z'
(1 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
\b the boundary between a word char (\w)
and something that is not a word char
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
[a-zA-Z0-9]* any character of: 'a' to 'z', 'A' to 'Z',
'0' to '9' (0 or more times (matching the
most amount possible)) 发布于 2022-05-16 21:25:22
您可以使用以下正则表达式:
\w*\d\w*解释:
\w*:字母数字字符的可选组合\d:数字\w*:字母数字字符的可选组合试试吧,这里。
编辑:如果需要显示至少一个字母和数字,则可以使用以下regex:
\w*(\d[A-Za-z]|[A-Za-z]\d)\w*解释:
\w*:字母数字字符的可选组合(\d[A-Za-z]|[A-Za-z]\d):\d[A-Za-z]|:数字+字母字符或[A-Za-z]\d:字母+数字\w*:字母数字字符的可选组合https://stackoverflow.com/questions/72265691
复制相似问题