1、打开myeclipse,准备编写java代码;
2、新建java类,
3、编写java代码,
package test;
import java.util.regex.Pattern;
public class TestRegexp {
public static void main(String[] args) {
String regex = "^A.*C.*B$";
Pattern p = Pattern.compile(regex);
java.util.regex.Matcher m = p.matcher("ACDB");
System.out.println("START");
while (m.find()) {
System.out.println(m.group());
}
}
}
4、执行,在consle中看到结果如下,匹配成功;
String regex = "^A*C*B$"; Pattern p = Pattern.compile(regex); java.util.regex.Matcher m = p.matcher("这里是你要匹配的字符串"); while (m.find()) { System.out.println(m.group()); }
A.*C.*B
^A.*C.*B$
String regex = "^A*C*B$";
Pattern p = Pattern.compile(regex);
java.util.regex.Matcher m = p.matcher("这里是你要匹配的字符串");
while (m.find()) {
System.out.println(m.group());
}