JAVA 正则表达式怎么写。。。查找 以A 开头 以B 结尾 中间包含字符串 C 的字符串。。。。
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中看到结果如下,匹配成功;
温馨提示:答案为网友推荐,仅供参考
第1个回答 2017-01-29
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()); }
第2个回答 2017-01-08
A.*C.*B
第3个回答 2015-05-27
^A.*C.*B$
第4个回答 2015-05-27
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());
}本回答被提问者和网友采纳
Pattern p = Pattern.compile(regex);
java.util.regex.Matcher m = p.matcher("这里是你要匹配的字符串");
while (m.find()) {
System.out.println(m.group());
}本回答被提问者和网友采纳