我知道字符串的确切前缀。
例如它是'XXX000‘
在前缀之后,有60个数字和字符。
这种情况下如何构造regexp?
在我最初的理解中,它应该是这样的:
(XXX000)(\w{*})like:前缀(一些数字或字符)
发布于 2010-10-08 23:29:22
使用此/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_]字符,请替换为您自己的字符类。
注意:您可能不需要分隔符,如果是这样,请记住删除它们。
资源:
发布于 2010-10-09 00:24:48
如果您需要恰好匹配60个字符,它是
XXX000\w{60}除非你需要捕捉比赛的一部分,否则没有必要对父母进行分组。http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html
https://stackoverflow.com/questions/3892021
复制相似问题