/** * 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); }
private String process(String textToParse) { Perl5Matcher matcher = new Perl5Matcher(); PatternMatcherInput input = new PatternMatcherInput(textToParse); PatternCacheLRU pcLRU = new PatternCacheLRU(); Pattern pattern; try { pattern = pcLRU.getPattern(regexpField.getText(), Perl5Compiler.READ_ONLY_MASK); } catch (MalformedCachePatternException e) { return e.toString(); } List<MatchResult> matches = new LinkedList<>(); while (matcher.contains(input, pattern)) { matches.add(matcher.getMatch()); } // Construct a multi-line string with all matches StringBuilder sb = new StringBuilder(); final int size = matches.size(); sb.append("Match count: ").append(size).append("\n"); for (int j = 0; j < size; j++) { MatchResult mr = matches.get(j); final int groups = mr.groups(); for (int i = 0; i < groups; i++) { sb.append("Match[").append(j+1).append("][").append(i).append("]=").append(mr.group(i)).append("\n"); } } return sb.toString(); }
public RegexFunction() { templatePattern = JMeterUtils.getPatternCache().getPattern(TEMPLATE_PATTERN, Perl5Compiler.READ_ONLY_MASK); }
/** * 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; } }
/** * 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)); }
/** * 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)); }
private void initRegex(String argName) { pathExtensionEqualsQuestionmarkRegexp = JMeterUtils.getPatternCache().getPattern( SEMI_COLON + quotedArg + "=([^\"'<>&\\s;]*)", // $NON-NLS-1$ Perl5Compiler.MULTILINE_MASK | Perl5Compiler.READ_ONLY_MASK); pathExtensionEqualsNoQuestionmarkRegexp = JMeterUtils.getPatternCache().getPattern( SEMI_COLON + quotedArg + "=([^\"'<>&\\s;?]*)", // $NON-NLS-1$ Perl5Compiler.MULTILINE_MASK | Perl5Compiler.READ_ONLY_MASK); pathExtensionNoEqualsQuestionmarkRegexp = JMeterUtils.getPatternCache().getPattern( SEMI_COLON + quotedArg + "([^\"'<>&\\s;]*)", // $NON-NLS-1$ Perl5Compiler.MULTILINE_MASK | Perl5Compiler.READ_ONLY_MASK); pathExtensionNoEqualsNoQuestionmarkRegexp = JMeterUtils.getPatternCache().getPattern( SEMI_COLON + quotedArg + "([^\"'<>&\\s;?]*)", // $NON-NLS-1$ Perl5Compiler.MULTILINE_MASK | Perl5Compiler.READ_ONLY_MASK); parameterRegexp = JMeterUtils.getPatternCache().getPattern(
/** * Returns true if matching pattern was different from expectedToMatch * @param expression Expression to match * @param sampleContentType * @return boolean true if Matching expression */ private boolean testPattern(String expression, String sampleContentType, boolean expectedToMatch) { if(expression != null && expression.length() > 0) { if(log.isDebugEnabled()) { log.debug( "Testing Expression : {} on sampleContentType: {}, expected to match: {}", expression, sampleContentType, expectedToMatch); } Pattern pattern = null; try { pattern = JMeterUtils.getPatternCache().getPattern(expression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK); if(JMeterUtils.getMatcher().contains(sampleContentType, pattern) != expectedToMatch) { return false; } } catch (MalformedCachePatternException e) { log.warn("Skipped invalid content pattern: {}", expression, e); } } return true; }
private boolean isFirstElementGroup(String rawData) { Pattern pattern = JMeterUtils.getPatternCache().getPattern("^\\$\\d+\\$", //$NON-NLS-1$ Perl5Compiler.READ_ONLY_MASK); return JMeterUtils.getMatcher().contains(rawData, pattern); }
String rawTemplate = getTemplate(); PatternMatcher matcher = JMeterUtils.getMatcher(); Pattern templatePattern = JMeterUtils.getPatternCache().getPattern("\\$(\\d+)\\$" // $NON-NLS-1$ , Perl5Compiler.READ_ONLY_MASK & Perl5Compiler.SINGLELINE_MASK);
private boolean matchesPatterns(String url, CollectionProperty patterns) { for (JMeterProperty jMeterProperty : patterns) { String item = jMeterProperty.getStringValue(); try { Pattern pattern = JMeterUtils.getPatternCache().getPattern( item, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK); if (JMeterUtils.getMatcher().matches(url, pattern)) { return true; } } catch (MalformedCachePatternException e) { log.warn("Skipped invalid pattern: {}", item, e); } } return false; }
private boolean isEquals(String subj) { Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue()); return JMeterUtils.getMatcher().matches(subj, pattern); }
private String filterString(final String content) { if (stringsToSkip == null || stringsToSkip.isEmpty()) { return content; } else { String result = content; for (SubstitutionElement regex : stringsToSkip) { emptySub.setSubstitution(regex.getSubstitute()); result = Util.substitute(JMeterUtils.getMatcher(), JMeterUtils.getPatternCache().getPattern(regex.getRegex()), emptySub, result, Util.SUBSTITUTE_ALL); } return result; } }
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()); } }
private boolean isEquals(Object subj) { String str = JSONPathExtractor.objectToString(subj); if (isUseRegex()) { Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue()); return JMeterUtils.getMatcher().matches(str, pattern); } else { return str.equals(getExpectedValue()); } }
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); }
Object[] tmplt; try { searchPattern = JMeterUtils.getPatternCache().getPattern(((CompoundVariable) values[0]).execute(), Perl5Compiler.READ_ONLY_MASK); tmplt = generateTemplate(((CompoundVariable) values[1]).execute());
org.apache.oro.text.regex.Pattern regex = JMeterUtils.getPatternCache().getPattern(entry.getKey()); PatternMatcher matcher = JMeterUtils.getMatcher(); if (sampleName != null && matcher.matches(sampleName, regex)) {
&& !matcher.matches(newLink.getPath(), patternCache.getPattern("[/]*" + path, // $NON-NLS-1$ Perl5Compiler.READ_ONLY_MASK))) { return false; final String name = item.getName(); if (!query.contains(name + "=")) { // $NON-NLS-1$ if (!(matcher.contains(query, patternCache.getPattern(name, Perl5Compiler.READ_ONLY_MASK)))) { return false;
pattern=JMeterUtils.getPatternCache().getPattern( REGEXP, Perl5Compiler.CASE_INSENSITIVE_MASK