2024-07-27 00:49:46
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Demo6 {
public static void main(String[] args) {
List<String> match = match("serfwrf1231234dfsf2445");
System.out.println(match);
}
public static List<String> match(String source) {
List<String> result = new ArrayList<String>();
String reg = "\\d*[^\\D*]";
Matcher m = Pattern.compile(reg).matcher(source);
while (m.find()) {
String r = m.group(0);
result.add(r);
}
return result;
}
}
2024-07-27 01:01:12
(\d+)
import java.util.regex.*;
// 表达式对象
Pattern p = Pattern.compile("(\\d+)");
// 创建 Matcher 对象
Matcher m = p.matcher("serfwrf1231234dfsf2445");
// 是否找到匹配
boolean found = m.find();
if( found )
{
String foundstring = m.group();
int beginPos = m.start();
int endPos = m.end();
}
2024-07-27 00:24:29
2024-07-27 01:53:26