正则表达式

正则表达式规则和前端的差不多

String1.matches(regex)

String1.replaceAll(regex,替换的内容)

真正的的正则表达式

Patten和 Matcher。。

需要impoty  java.util.regex.*;

先来一条正则表达式String: String regex="(http://|www)\56?\\w+\56{1}\\w+\56{1}\\p{Alpha}+";

用 Patten p=Patten.compile(regex) 把正则编译一下

把编译的通过 p.matcher(a )交个Matcher

String string1="新浪:www.sina.cn,央视:http:\\www.cctv.com";
Matcher m=p.matcher(string1);

public boolean find()//如果有匹配到返回一个true

public String replaceAll(String a)//匹配到的内容用 String a代替,返回修改后的String ,不影响以前的串

m.group()捕获到的数据

posted on 2016-10-09 22:56  Kooing  阅读(250)  评论(0编辑  收藏  举报

导航