gpt4 book ai didi

java - 数字和任意长度的正则表达式

转载 作者:行者123 更新时间:2023-11-29 08:17:02 27 4
gpt4 key购买 nike

我知道字符串的确切前缀。

例如这是'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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com