use of org.apache.oro.text.regex.Perl5Matcher in project bboss by bbossgroups.
the class RegexUtil method isMatch.
/**
* 检查src与正则表达式regex匹配结果
* @param src String
* @param regex String
* @return boolean
*/
public static boolean isMatch(String src, String regex) {
if (src == null)
return false;
boolean flag = false;
String patternStr = regex;
/**
* 编译正则表达式patternStr,并用该表达式与传入的src字符串进行模式匹配,
* 如果匹配正确,则从匹配对象中提取出以上定义好的6部分,存放到数组中并返回
* 该数组
*/
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = null;
try {
pattern = compiler.compile(patternStr, default_mask);
} catch (MalformedPatternException e) {
e.printStackTrace();
return false;
}
PatternMatcher matcher = new Perl5Matcher();
// log.debug("src:" + src);;
// log.debug("pattern:" + pattern);
// log.debug("regex:" + regex);
flag = matcher.matches(src, pattern);
return flag;
}
use of org.apache.oro.text.regex.Perl5Matcher in project bboss by bbossgroups.
the class RegexUtil method isContain.
public static boolean isContain(String src, String regex) {
if (src == null)
return false;
String patternStr = regex;
/**
* 编译正则表达式patternStr,并用该表达式与传入的src字符串进行模式匹配,
* 如果匹配正确,则从匹配对象中提取出以上定义好的6部分,存放到数组中并返回
* 该数组
*/
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = null;
try {
pattern = compiler.compile(patternStr, default_mask);
} catch (MalformedPatternException e) {
e.printStackTrace();
return false;
}
PatternMatcher matcher = new Perl5Matcher();
return matcher.contains(src, pattern);
}
use of org.apache.oro.text.regex.Perl5Matcher in project bboss by bbossgroups.
the class RegexUtil method containWithPatternMatcherInput.
/**
* 从src中提取包含模式regex的子字符串
* @param src
* @param regex
* @return
*/
public static String[] containWithPatternMatcherInput(String src, String regex) {
String patternStr = regex;
/**
* 编译正则表达式patternStr,并用该表达式与传入的src字符串进行模式匹配,
* 如果匹配正确,则从匹配对象中提取出以上定义好的6部分,存放到数组中并返回
* 该数组
*/
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = null;
try {
pattern = compiler.compile(patternStr, default_mask);
} catch (MalformedPatternException e) {
e.printStackTrace();
return null;
}
PatternMatcher matcher = new Perl5Matcher();
MatchResult result = null;
String[] tokens = null;
List<String> sets = new ArrayList<String>();
PatternMatcherInput input = new PatternMatcherInput(src);
while (matcher.contains(input, pattern)) {
result = matcher.getMatch();
int size = result.groups();
for (int i = 1; i < size; i++) {
sets.add(result.group(i));
}
}
tokens = new String[sets.size()];
sets.toArray(tokens);
return tokens;
}
use of org.apache.oro.text.regex.Perl5Matcher in project bboss by bbossgroups.
the class RegexUtil method contain.
/**
* 从包含
* @param src
* @param regex
* @return
*/
public static String[] contain(String src, String regex) {
String patternStr = regex;
/**
* 编译正则表达式patternStr,并用该表达式与传入的src字符串进行模式匹配,
* 如果匹配正确,则从匹配对象中提取出以上定义好的6部分,存放到数组中并返回
* 该数组
*/
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = null;
try {
pattern = compiler.compile(patternStr, default_mask);
} catch (MalformedPatternException e) {
e.printStackTrace();
return null;
}
PatternMatcher matcher = new Perl5Matcher();
MatchResult result = null;
String[] tokens = null;
if (matcher.contains(src, pattern)) {
result = matcher.getMatch();
int size = result.groups() - 1;
tokens = new String[size];
for (int i = 0; i < size; i++) {
tokens[i] = result.group(i + 1);
}
}
return tokens;
}
use of org.apache.oro.text.regex.Perl5Matcher in project bboss by bbossgroups.
the class TestInsertSqlParser method main.
public static void main(String[] args) throws MalformedPatternException {
String insert = "Insert into oa_meetingpromptsound ( soundCode , soundName , soundFileName ) values ( '。.尹标平','bb','d()d' )";
// String pattern = "(insert) \\t*(into) \\s*([a-z0-9A-Z_\\-]+)\\s*\\([a-z0-9A-Z_\\-]+\\s*,\\s*[a-z0-9A-Z_\\-]+)";
// String pattern = "(insert)\\s+(into)\\s+([a-z0-9A-Z_\\-]+)\\s*(\\([^\\)]\\))\\s+([^\\s])";
String patternStr = // 解析insert关键词
"(insert)\\s+" + // 解析into关键词
"(into)\\s+" + // 解析表名称
"([^\\(]+)\\s*" + // 解析表字段
"(\\([^\\)]+\\))\\s+" + // 解析value关键词
"(values)\\s*" + // 解析字段值
"(\\(.+)";
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = compiler.compile(patternStr, Perl5Compiler.CASE_INSENSITIVE_MASK);
PatternMatcher matcher = new Perl5Matcher();
MatchResult result = null;
if (matcher.matches(insert.trim(), pattern)) {
result = matcher.getMatch();
System.out.println(result.group(1));
System.out.println(result.group(2));
System.out.println(result.group(3));
System.out.println(result.group(4));
System.out.println(result.group(5));
System.out.println(result.group(6));
}
}
Aggregations