Search in sources :

Example 1 with PatternCompiler

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);
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.shared.common.BaseOtterTest)

Example 2 with PatternCompiler

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;
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 3 with PatternCompiler

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;
    }
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 4 with PatternCompiler

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);
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) StringProperty(org.apache.jmeter.testelement.property.StringProperty) StringSubstitution(org.apache.oro.text.regex.StringSubstitution) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 5 with PatternCompiler

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;
    }
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Aggregations

MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)8 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)8 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)8 Pattern (org.apache.oro.text.regex.Pattern)6 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)6 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)5 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)2 BaseOtterTest (com.alibaba.otter.shared.common.BaseOtterTest)1 ConfigException (com.alibaba.otter.shared.common.model.config.ConfigException)1 StringProperty (org.apache.jmeter.testelement.property.StringProperty)1 StringSubstitution (org.apache.oro.text.regex.StringSubstitution)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)1 Test (org.testng.annotations.Test)1