加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则Pattern Matcher compile matcher find group(.*?)

发布时间:2020-12-14 01:14:42 所属栏目:百科 来源:网络整理
导读:正则Pattern Matcher compile matcher find group(.*?) public static void main(String[] args) { String str = "http://funds.hexun.com/2015-05-28/176237903.html"; Pattern pattern = Pattern.compile("http://(.*?).hexun.com(.*?).html");

正则Pattern Matcher compile matcher find group(.*?)

public static void main(String[] args) { String str = "http://funds.hexun.com/2015-05-28/176237903.html"; Pattern pattern = Pattern.compile("http://(.*?).hexun.com(.*?).html"); Matcher matcher = pattern.matcher(str); while (matcher.find()) { System.out.println("Group0=:" + matcher.group(0));// 得到第0组——整个匹配 System.out.println("Group1=:" + matcher.group(1));// 得到第一组匹配——与(or)匹配的 System.out.println("Group2=:" + matcher.group(2));// 得到第二组匹配——与(ld!)匹配的,组也就是子表达式 System.out.println("Start0=:" + matcher.start(0) + " End0:=" + matcher.end(0));// 总匹配的索引 System.out.println("Start1=:" + matcher.start(1) + " End1:=" + matcher.end(1));// 第一组匹配的索引 System.out.println("Start2=:" + matcher.start(2) + " End2=:" + matcher.end(2));// 第二组匹配的索引 System.out.println(str.substring(matcher.start(0),matcher.end(1)));// 从总匹配开始索引到第1组匹配的结束索引之间子串——Wor } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读