在android中,从字符串中提取子字符串的最佳方法是什么?
发布于 2019-03-30 07:42:09
查找匹配模式的子字符串的多个匹配项时
String input_string = "foo/adsfasdf/adf/bar/erqwer/";
String regex = "(foo/|bar/)"; // Matches 'foo/' and 'bar/'
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input_string);
while(matcher.find()) {
String str_matched = input_string.substring(matcher.start(), matcher.end());
// Do something with a match found
}https://stackoverflow.com/questions/5414657
复制相似问题