http://deerchao.net/tutorials/regex/regex.htm#lookaround
代码展现
package test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexUtil {
public static void main(String[] args) {
/*** * .*(?=>) 600 * * (?<=>=)+.*(?=and) 2 * * (?<=\\()+.*(?=!=) int * 其中:\\为转义字符 * (?<=!=)+.*(?=or) int * * (?<=or)+.*(?=<=) 2 * * (?<=<=)+.*(?=\\)) 600 */
String input = "600>=2 and (int != int or 2 <= 600)";
String regex = "(?<=<=)+.*(?=\\))";
System.out.println(Match(input,regex));
}
/** * * 正则表达式辅助类 * * @param input 字符串 * @param regex 正则表达式 * @return 正则表达式匹配结果 */
public static String Match(String input,String regex) {
Pattern praiseCompile = Pattern.compile(regex);
Matcher praiseMatcher = praiseCompile.matcher(input);
if (praiseMatcher.find()) {
return praiseMatcher.group(0).trim();
}
return null;
}
}