gpt4 book ai didi

java - 在 java 中匹配 update_1_0_3_to_1_0_4 的正则表达式

转载 作者:行者123 更新时间:2023-12-03 23:02:33 26 4
gpt4 key购买 nike

在 java 中匹配以下字符串的正确正则表达式是什么?

update_1_0_3_to_1_0_4

我试过了

boolean t1= files.matches("^update_\\d_\\d_\\d{1,2}$\\_to_\\d_\\d_\\d{1,2}$");
System.out.println("The strings match " + t1);

但是,它不起作用,因此返回 false。

最佳答案

"^update_\\d_\\d_\\d{1,2}_to_\\d_\\d_\\d{1,2}$"

我所做的只是从中间删除 $\\$ 表示字符串结尾(当然,它应该只在结尾)并且 _ 不需要转义,所以 \\ 在没有必要之前。

关于java - 在 java 中匹配 update_1_0_3_to_1_0_4 的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16825632/

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