C# 正则表达式的使用,匹配多组数据,如何逐个提取?

2025-03-28 23:43:01
推荐回答(1个)
回答1:

用非贪婪模式的正则表达式 [\s\S]*?

就是比贪婪模式的正则表达式多了个问号

我给你个Java语言的例子,你看看吧

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class BB {
 public static void main(String[] args) {
  String reciveString="0成功419611922资源上传服务4000419611923WEB站点监控4000";
  String regex="[\\s\\S]*?";
  Pattern p=Pattern.compile(regex);
  Matcher m=p.matcher(reciveString);
  while(m.find()){
   System.out.println(m.group());
  }
 }
}

运行结果

419611922资源上传服务4000
419611923WEB站点监控4000