String str = "Locaton;RowIndex;maxRows=New York, NY_10007;1;4 ";
Pattern pattern = Pattern.compile("=(.*?),");
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
System.out.println(matcher.group(1));
}
输出:
New York
Using matcher.group(1) means capturing groups make it easy to extract part of the regex match,parentheses also create a numbered capturing group.
It stores the part of the string matched by the part of the regular expression inside the parentheses.
Match "Locaton;RowIndex;maxRows=New York, NY_10007;1;4 "
Group 1: "New York"
使用带有正则表达式的捕获组可以完美地捕获字符串中的特定数据
这是输出
尝试如下使用此正则表达式
"=(.*?),"
:输出:
相关问题 更多 >
编程相关推荐