正则:零宽断言和负向零宽断言
发布时间:2020-12-14 04:28:17 所属栏目:百科 来源:网络整理
导读: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 * * (?==)+
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;
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |