java如何使用模式匹配获取特定字符后的字符串?
String tect = "A to B";
Pattern ptrn = Pattern.compile("\\b(A.*)\\b");
Matcher mtchr = ptrn.matcher(tr.text());
while(mtchr.find()) {
System.out.println( mtchr.group(1) );
}
我正在获得输出A to B
,但我想要to B
请帮帮我
你可以在下面搜索框中键入要查询的问题!
String tect = "A to B";
Pattern ptrn = Pattern.compile("\\b(A.*)\\b");
Matcher mtchr = ptrn.matcher(tr.text());
while(mtchr.find()) {
System.out.println( mtchr.group(1) );
}
我正在获得输出A to B
,但我想要to B
请帮帮我
# 1 楼答案
你可以把
A
放在你的捕获组之外你也可以把绳子分开
# 2 楼答案
你可以在一行中完成:
# 3 楼答案
将模式更改为使用look behind positive断言检查
A
: