Search in sources :

Example 36 with Pattern

use of org.apache.oro.text.regex.Pattern in project jmeter by apache.

the class MultipartUrlConfig method getHeaderValue.

private static String getHeaderValue(String headerName, String multiPart) {
    // $NON-NLS-1$
    String regularExpression = headerName + "\\s*:\\s*(.*)$";
    Perl5Matcher localMatcher = JMeterUtils.getMatcher();
    Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
    if (localMatcher.contains(multiPart, pattern)) {
        return localMatcher.getMatch().group(1).trim();
    } else {
        return null;
    }
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher)

Example 37 with Pattern

use of org.apache.oro.text.regex.Pattern in project otter by alibaba.

the class ActionProtectedEditor method convertStringToPattern.

/**
 * 把字符串转成Pattern和UrlType
 *
 * @param perl5RegExp
 * @return
 */
private ActionPatternHolder convertStringToPattern(String line) {
    ActionPatternHolder holder = new ActionPatternHolder();
    String[] strs = org.apache.commons.lang.StringUtils.split(line, "|");
    if (strs.length != 2) {
        throw new IllegalArgumentException("illegal expression: " + line);
    }
    Pattern compiledPattern;
    Perl5Compiler compiler = new Perl5Compiler();
    try {
        holder.setActionName(strs[0]);
        compiledPattern = compiler.compile(strs[0], Perl5Compiler.READ_ONLY_MASK);
        holder.setActionPattern(compiledPattern);
    } catch (MalformedPatternException mpe) {
        throw new IllegalArgumentException("Malformed regular expression: " + strs[0]);
    }
    try {
        holder.setMethodName(strs[1]);
        compiledPattern = compiler.compile(strs[1], Perl5Compiler.READ_ONLY_MASK);
        holder.setMethodPattern(compiledPattern);
    } catch (MalformedPatternException mpe) {
        throw new IllegalArgumentException("Malformed regular expression: " + strs[1]);
    }
    return holder;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 38 with Pattern

use of org.apache.oro.text.regex.Pattern in project otter by alibaba.

the class URLProtectedEditor method convertStringToPattern.

/**
 * 把字符串转成Pattern和UrlType
 *
 * @param perl5RegExp
 * @return
 */
private URLPatternHolder convertStringToPattern(String line) {
    URLPatternHolder holder = new URLPatternHolder();
    Pattern compiledPattern;
    Perl5Compiler compiler = new Perl5Compiler();
    String perl5RegExp = line;
    try {
        compiledPattern = compiler.compile(perl5RegExp, Perl5Compiler.READ_ONLY_MASK);
        holder.setCompiledPattern(compiledPattern);
    } catch (MalformedPatternException mpe) {
        throw new IllegalArgumentException("Malformed regular expression: " + perl5RegExp);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Added regular expression: " + compiledPattern.getPattern().toString());
    }
    return holder;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 39 with Pattern

use of org.apache.oro.text.regex.Pattern 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 40 with Pattern

use of org.apache.oro.text.regex.Pattern in project intellij-plugins by JetBrains.

the class GherkinPsiUtil method buildParameterRanges.

@Nullable
public static List<TextRange> buildParameterRanges(@NotNull GherkinStep step, @NotNull AbstractStepDefinition definition, final int shiftOffset) {
    final List<TextRange> parameterRanges = new ArrayList<>();
    final Pattern pattern = definition.getPattern();
    if (pattern == null)
        return null;
    final Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.contains(step.getStepName(), pattern)) {
        final MatchResult match = matcher.getMatch();
        final int groupCount = match.groups();
        for (int i = 1; i < groupCount; i++) {
            final int start = match.beginOffset(i);
            final int end = match.endOffset(i);
            if (start >= 0 && end >= 0) {
                parameterRanges.add(new TextRange(start, end).shiftRight(shiftOffset));
            }
        }
    }
    int k = step.getText().indexOf(step.getStepName());
    k += step.getStepName().length();
    if (k < step.getText().length() - 1) {
        String text = step.getText().substring(k + 1);
        boolean inParam = false;
        int paramStart = 0;
        int i = 0;
        while (i < text.length()) {
            if (text.charAt(i) == '<') {
                paramStart = i;
                inParam = true;
            }
            if (text.charAt(i) == '>' && inParam) {
                parameterRanges.add(new TextRange(paramStart, i + 1).shiftRight(shiftOffset + step.getStepName().length() + 1));
                inParam = false;
            }
            i++;
        }
    }
    return parameterRanges;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Pattern (org.apache.oro.text.regex.Pattern)70 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)48 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)27 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)24 MatchResult (org.apache.oro.text.regex.MatchResult)17 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)14 ArrayList (java.util.ArrayList)12 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)9 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)7 IOException (java.io.IOException)6 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)6 MalformedURLException (java.net.MalformedURLException)4 BufferedReader (java.io.BufferedReader)3 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)3 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)3 EOFException (java.io.EOFException)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2