我知道字符串的确切前缀。
例如这是'XXX000'
在前缀、数字和字符之后,数量为 60 go。
如何构造正则表达式?
在我最初的理解中它应该是这样的:
(XXX000)(\w{*})
喜欢: 前缀(一些数字或一些字符)
最佳答案
使用这个/XXX000(\w{0,60})/
/ <- Start of the regex
XXX000 <- Your constant prefix (don't really need to capture it then)
( <- Capture the following matching elements
\w <- Every characters in [a-zA-Z0-9_]
{0,60} <- Between 0 and 60 repetitions of the last element
) <- End of the group
/ <- End of the regex
如果您不想要 [a-zA-Z0-9_]
字符,请替换为您自己的字符类。
注意:您可能不需要分隔符,如果是这种情况,请记住将其删除。
资源:
关于java - 数字和任意长度的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3892021/