use of org.apache.oro.text.regex.PatternCompiler in project otter by alibaba.
the class ConfigHelperTest method testWildCard.
@Test
public void testWildCard() {
PatternMatcher matcher = new Perl5Matcher();
Pattern pattern = null;
PatternCompiler pc = new Perl5Compiler();
try {
pattern = pc.compile("havana_us_.*", Perl5Compiler.DEFAULT_MASK);
} catch (MalformedPatternException e) {
throw new ConfigException(e);
}
boolean ismatch = matcher.matches("havana_us_0001", pattern);
System.out.println(ismatch);
}
use of org.apache.oro.text.regex.PatternCompiler in project tdi-studio-se by Talend.
the class MapDataDelegateHelper method matchExpression.
private boolean matchExpression(String regex, String expression) {
PatternCompiler compiler = new Perl5Compiler();
try {
//$NON-NLS-1$ //$NON-NLS-2$
Pattern pattern = compiler.compile("\\b(" + UpdateContextVariablesHelper.replaceSpecialChar(regex) + ")(\\b|\\_)");
PatternMatcher matcher = new Perl5Matcher();
((Perl5Matcher) matcher).setMultiline(true);
if (matcher.contains(expression, pattern)) {
return true;
}
} catch (MalformedPatternException e) {
//
}
return false;
}
use of org.apache.oro.text.regex.PatternCompiler in project tdi-studio-se by Talend.
the class NodeQueryCheckUtil method apacheRegexMatch.
/**
* See bug 5836. java.util.regex works too slow here. Use apache oro regex library instead.
* <p>
* DOC xye Comment method "apacheRegexMatch".
*
* @param patternString
* @param flag
* @param input
* @return
*/
private static boolean apacheRegexMatch(final String patternString, final int flag, final String input) {
PatternCompiler pc = new Perl5Compiler();
org.apache.oro.text.regex.Pattern pattern = null;
try {
pattern = pc.compile(patternString, flag);
PatternMatcher columnMatcher = new Perl5Matcher();
return columnMatcher.matches(input, pattern);
} catch (MalformedPatternException e) {
return false;
}
}
use of org.apache.oro.text.regex.PatternCompiler in project jmeter by apache.
the class ReplaceFunctionsWithStrings method transformValue.
@Override
public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException {
PatternMatcher pm = JMeterUtils.getMatcher();
PatternCompiler compiler = new Perl5Compiler();
String input = prop.getStringValue();
if (input == null) {
return prop;
}
for (Entry<String, String> entry : getVariables().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (regexMatch) {
try {
Pattern pattern = compiler.compile(constructPattern(value));
input = Util.substitute(pm, pattern, new StringSubstitution(FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX), input, Util.SUBSTITUTE_ALL);
} catch (MalformedPatternException e) {
log.warn("Malformed pattern: {}", value);
}
} else {
input = StringUtilities.substitute(input, value, FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX);
}
}
return new StringProperty(prop.getName(), input);
}
use of org.apache.oro.text.regex.PatternCompiler in project tdi-studio-se by Talend.
the class AbstractMapComponent method getRenamePattern.
protected final Pattern getRenamePattern(String oldName) {
if (patternsCache.containsKey(oldName)) {
return patternsCache.get(oldName);
}
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = null;
try {
//$NON-NLS-1$ //$NON-NLS-2$
pattern = compiler.compile("\\b(" + UpdateContextVariablesHelper.replaceSpecialChar(oldName) + ")(\\b|\\_)");
patternsCache.put(oldName, pattern);
return pattern;
} catch (MalformedPatternException e) {
ExceptionHandler.process(e);
return null;
}
}
Aggregations