/** * Get a compiled expression from the pattern cache. * * @param expression RE * @param options e.g. {@link Perl5Compiler#READ_ONLY_MASK READ_ONLY_MASK} * @return compiled pattern * * @throws MalformedCachePatternException (Runtime) * This should be caught for expressions that may vary (e.g. user input) * */ public static Pattern getPattern(String expression, int options) throws MalformedCachePatternException { return LazyPatternCacheHolder.INSTANCE.getPattern(expression, options); }
public Recurser(Connection connection) { super(connection); this.globCompiler = new GlobCompiler(); this.matcher = new Perl5Matcher(); }
GlobCompiler gc = new GlobCompiler(); try { Perl5Pattern pattern = (Perl5Pattern) gc.compile("[JKL][DEF][DEF]"); Perl5Matcher matcher = new Perl5Matcher(); String straw = "JEEVES"; if (matcher.matchesPrefix(straw, pattern)) { MatchResult res = matcher.getMatch(); for (int i = 0; i < res.groups(); i++) { String s = straw.substring(res.beginOffset(i), res.endOffset(i)); // 's' now contains a the match of group #i } } else { // No match } } catch (MalformedPatternException e) { // Oh noes }
public List<String> getAllMatches(String content, String spattern, int group) throws MalformedPatternException { List<String> list = new ArrayList<String>(); PatternMatcherInput input = new PatternMatcherInput(content); Pattern pattern = patterns.addPattern(spattern); while (this.matcher.contains(input, pattern)) { MatchResult result = this.matcher.getMatch(); String smatch = result.group(group); list.add(smatch); } return list; }
protected String getIpAddress(String logLine) { Pattern incIp = JMeterUtils.getPatternCache().getPattern("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}", Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK); Perl5Matcher matcher = JMeterUtils.getMatcher(); matcher.contains(logLine, incIp); return matcher.getMatch().group(0); }
/** * Match the input argument against the pattern using String.equals() or pattern matching if that fails. * * @param arg input string * @param pat pattern string * @param matcher Perl5Matcher * @param cache PatternCache * * @return true if input matches the pattern */ public static boolean isEqualOrMatches(String arg, String pat, Perl5Matcher matcher, PatternCacheLRU cache){ return arg.equals(pat) || matcher.matches(arg,cache.getPattern(pat,Perl5Compiler.READ_ONLY_MASK)); }
public void setUrlPattern(String urlPattern) { this.urlPattern = urlPattern; this.pattern = null; try { PatternCompiler compiler = new GlobCompiler(); this.pattern = compiler.compile(this.urlPattern); } catch (Exception e) { log.error("Invalid url pattern: " + this.urlPattern); } }
public GlobMatcher(String expression) throws PatternSyntaxException { this.expression = expression; try { pattern = new GlobCompiler().compile(expression); } catch (MalformedPatternException e) { throw new PatternSyntaxException(e.getMessage(), expression, 0); } }
private boolean matches(String pattern, String path) throws FinderException { Pattern compiled; try { compiled = this.globCompiler.compile(pattern); } catch (MalformedPatternException e) { throw new FinderException("Bad glob pattern: " + pattern, e); } path = basename(path); return this.matcher.matches(path, compiled); }
private boolean isFirstElementGroup(String rawData) { Pattern pattern = JMeterUtils.getPatternCache().getPattern("^\\$\\d+\\$", //$NON-NLS-1$ Perl5Compiler.READ_ONLY_MASK); return JMeterUtils.getMatcher().contains(rawData, pattern); }
public Pattern compilePattern(String patternStr) throws MalformedPatternException { int globOptions = GlobCompiler.DEFAULT_MASK | GlobCompiler.QUESTION_MATCHES_ZERO_OR_ONE_MASK; char [] patternCh = patternStr.toCharArray(); String perl5PatternStr = GlobCompiler.globToPerl5(patternCh, globOptions); return super.compilePattern(perl5PatternStr); } }
public void setPattern(String patternparam, int options) { setPattern(Util.getPatterns().getPattern(makePattern(patternparam), options)); }
/** * Match the input argument against the pattern using String.equals() or pattern matching if that fails * using case-insensitive matching. * * @param arg input string * @param pat pattern string * @param matcher Perl5Matcher * @param cache PatternCache * * @return true if input matches the pattern */ public static boolean isEqualOrMatchesCaseBlind(String arg, String pat, Perl5Matcher matcher, PatternCacheLRU cache){ return arg.equalsIgnoreCase(pat) || matcher.matches(arg,cache.getPattern(pat,Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK)); }
public RegexFunction() { templatePattern = JMeterUtils.getPatternCache().getPattern(TEMPLATE_PATTERN, Perl5Compiler.READ_ONLY_MASK); }
protected Pattern compilePattern(String patternStr) throws MalformedPatternException { int globOptions = GlobCompiler.QUESTION_MATCHES_ZERO_OR_ONE_MASK; char [] patternCh = patternStr.toCharArray(); String perl5PatternStr = GlobCompiler.globToPerl5(patternCh, globOptions); return super.compilePattern(perl5PatternStr); }
public void setPattern(String patternparam) { setPattern(Util.getPatterns().getPattern(makePattern(patternparam))); }
private boolean isEquals(String subj) { Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue()); return JMeterUtils.getMatcher().matches(subj, pattern); }
/** * create a new pattern object from the string. * * @param pattern * string representation of the perl5 compatible regex pattern * @return compiled Pattern, or <code>null</code> if no pattern could be * compiled */ public Pattern createPattern(String pattern) { try { return JMeterUtils.getPatternCache().getPattern(pattern, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK); } catch (MalformedCachePatternException exception) { log.error("Problem with pattern: "+pattern,exception); return null; } }
public WikiSubstitution(Util util, String[] patternparam) { this.setPattern(Util.getPatterns().getPattern(makePattern(patternparam))); setSubstitution("$&"); }
private boolean isEquals(Object subj) { String str = objectToString(subj); if (isUseRegex()) { Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue()); return JMeterUtils.getMatcher().matches(str, pattern); } else { return str.equals(getExpectedValue()); } }