够用正则表达式

2020-03-24  本文已影响0人  富多多

问号的几种用途

Java中的正则表达式

String wd = "低温 16 ℃";
Pattern pattern = Pattern.compile(".*?(\\d+).*");
Matcher matcher = pattern.matcher(wd);
matcher.matches();
System.out.println(matcher.group(0));
System.out.println(matcher.group(1));

低温 16 ℃
16
String wd = "低温 16 ℃ 99";
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(wd);
while (matcher.find()) {
    System.out.println(matcher.group());
}

16
99

字符使用

正则表达式参考

上一篇 下一篇

猜你喜欢

热点阅读