//向后匹配
String a = "I paid $90 for 10 oranges, 12 pears and 8 apples. I saved $5 on ";
Pattern p = Pattern.compile("(?<=\\$)\\d+");
Matcher m = p.matcher(a);
while (m.find ())
{
String group = m.group ();
System.out.println (group);
}
向前匹配
a = "https://mail.huawei.com ";
p = Pattern.compile(".+(?=:)");
m = p.matcher(a);
while (m.find ())
{
String group = m.group ();
System.out.println (group);
}
Java 正则表达式 向前、向后匹配,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/kevinge/p/3829679.html