更新时间:2022-05-12 10:26:34
在JavaScript match
中返回与使用的正则表达式匹配的子字符串.在Java中, matches
检查整个字符串是否与正则表达式匹配.
In JavaScript match
returns substrings which matches used regex. In Java matches
checks if entire string matches regex.
如果要查找与正则表达式匹配的子字符串,请使用Pattern和Matcher类,如
If you want to find substrings that match regex use Pattern and Matcher classes like
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(yourData);
while(m.find()){
m.group();//this will return current match in each iteration
//you can also use other groups here using their indexes
m.group(2);
//or names (?<groupName>...)
m.group("groupName");
}