有人可以帮我使用正则表达式来匹配包含 3 个字母数字字符或 1 个星号字符的组吗?
任何01A
A12
a12
01a
等,或者*
我需要提取 3 个字母数字或 *,以存在者为准。
我试过了
([\\w]{3}|[\\*])
([\\w]{3})|([\\*])
和其他几个。没有任何效果。
谢谢。
I wish you'd have tried first, but this is a simple one. We can match alphanumeric characters by saying [a-zA-Z0-9]
, or we can match an asterisk by escaping it \*
. We use the pipe to match one of several alternatives (A|B|CDE)
, and we can put a number in braces to match more than one of something A{2}
. So, that should help you find the answer. If you try to put it together on your own, we'll help you along if you have any issues.