日期:2014-05-20 浏览次数:20821 次
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String[] args) { String A = "张江路"; String B = "碧波大道"; Pattern p = Pattern.compile(A + "\\d.*" + B); Matcher m = p.matcher("张江路12p碧波大道295"); while(m.find()){ System.out.println("false"); } } }
------解决方案--------------------
String str = "aaaaa222bbbb"; String A = "aaa"; String B = "bbb"; Pattern p = Pattern.compile((A + "*?" + B)); Matcher m = p.matcher(str); while(m.find()){ String temp = m.group(); System.out.println(temp + "\t" + temp.matches(A +"[^\\d].*?" + B)); }