/** * Does the given argument match the pattern? * @param input the string to match against * @param options the regex options to use * @return true if the pattern matches * @throws BuildException on error */ @Override public boolean matches(final String input, final int options) throws BuildException { return matcher.contains(input, getCompiledPattern(options)); }
/** * Returns true if the given String is matched by the regular expression of this RegExpEvaluator * * @param value the String to check the production of * @return true if the given string matches the regular expression of this RegExpEvaluator * @see #setExpression **/ public boolean matches(String value) { // object to match compiled regular expressions Perl5Matcher matcher = new Perl5Matcher(); // class for accessing results of pattern match return matcher.contains(value, _regexp); } // -- matches
/** * By default, the method assumes the entry is not included, unless it * matches. In that case, it will return true. * * @param text text to be checked * @return <code>true</code> if text is included */ protected boolean incPattern(String text) { this.USEFILE = false; for (Pattern includePattern : this.INCPATTERNS) { if (JMeterUtils.getMatcher().contains(text, includePattern)) { this.USEFILE = true; break; } } return this.USEFILE; }
/** * Returns true if the given String is matched by the * regular expression of this RegExpEvaluator * * @param value the String to check the production of * @return true if the given string matches the regular * expression of this RegExpEvaluator * @see #setExpression **/ public boolean matches(String value) { // object to match compiled regular expressions Perl5Matcher matcher = new Perl5Matcher(); // class for accessing results of pattern match return matcher.contains(value,_regexp); } //-- matches
/** * The method assumes by default the text is not excluded. If the text * matches the pattern, it will then return true. * * @param text text to be checked * @return <code>true</code> if text is excluded */ protected boolean excPattern(String text) { this.USEFILE = true; boolean exc = false; for (Pattern excludePattern : this.EXCPATTERNS) { if (JMeterUtils.getMatcher().contains(text, excludePattern)) { exc = true; this.USEFILE = false; break; } } return exc; }
/** * Checks that the message for an exception matches a regular expression. */ protected void assertExceptionRegexp(Throwable ex, String pattern) throws Exception { String message = ex.getMessage(); assertNotNull(message); setupMatcher(); Pattern compiled = _compiler.compile(pattern); if (_matcher.contains(message, compiled)) return; throw new AssertionFailedError("Exception message (" + message + ") does not contain regular expression [" + pattern + "]."); }
protected void assertRegexp(String pattern, String actual) throws Exception { setupMatcher(); Pattern compiled = _compiler.compile(pattern); if (_matcher.contains(actual, compiled)) return; throw new AssertionFailedError("\"" + actual + "\" does not contain regular expression[" + pattern + "]."); }
private int matchStrings(int matchNumber, Perl5Matcher matcher, Pattern pattern, List<MatchResult> matches, int found, String inputString) { PatternMatcherInput input = new PatternMatcherInput(inputString); while (matchNumber <=0 || found != matchNumber) { if (matcher.contains(input, pattern)) { log.debug("RegexExtractor: Match found!"); matches.add(matcher.getMatch()); found++; } else { break; } } return found; }
protected void assertLoggedMessagePattern(String pattern, List events) throws Exception { setupMatcher(); Pattern compiled = null; int count = events.size(); for (int i = 0; i < count; i++) { LoggingEvent e = (LoggingEvent) events.get(i); String eventMessage = e.getMessage().toString(); if (compiled == null) compiled = _compiler.compile(pattern); if (_matcher.contains(eventMessage, compiled)) return; } throw new AssertionFailedError("Could not find logged message with pattern: " + pattern); }
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; }
/** * 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); }
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(); }
private static String getHeaderValue(String headerName, String multiPart) { String regularExpression = headerName + "\\s*:\\s*(.*)$"; //$NON-NLS-1$ 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; } } }
public void filterRendering(String input) { contentBuffer=null; content=input; // match regular expression Perl5Matcher matcher=(Perl5Matcher)localMatcher.get(); PatternMatcherInput matcherInput=new PatternMatcherInput(content); while(matcher.contains(matcherInput,pattern)) { // construct a matchresult with corrected offsetts, if the buffer is present if(contentBuffer!=null && contentBuffer.length()!=content.length()) { processMatch(new CorrectedOffsetMatch(matcher.getMatch(),content.length()-contentBuffer.length())); } else { processMatch(matcher.getMatch()); } } if(contentBuffer!=null) { downstreamComponent.filterRendering(contentBuffer.toString()); } else { downstreamComponent.filterRendering(content); } }
private static String getRequestHeaderValue(String requestHeaders, String headerName) { Perl5Matcher localMatcher = JMeterUtils.getMatcher(); // We use multi-line mask so can prefix the line with ^ String expression = "^" + headerName + ":\\s+([^\\r\\n]+)"; // $NON-NLS-1$ $NON-NLS-2$ Pattern pattern = JMeterUtils.getPattern(expression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK); if(localMatcher.contains(requestHeaders, pattern)) { // The value is in the first group, group 0 is the whole match return localMatcher.getMatch().group(1); } else { return null; } }
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); }
private static int getPositionOfBody(String stringToCheck) { Perl5Matcher localMatcher = JMeterUtils.getMatcher(); // The headers and body are divided by a blank line (the \r is to allow for the CR before LF) String regularExpression = "^\\r$"; // $NON-NLS-1$ Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK); PatternMatcherInput input = new PatternMatcherInput(stringToCheck); if(localMatcher.contains(input, pattern)) { MatchResult match = localMatcher.getMatch(); return match.beginOffset(0); } // No divider was found return -1; } }
if (matcher.contains(input, pattern)) { MatchResult result = matcher.getMatch(); if (firstResult == null || result.beginOffset(0) < firstResult.beginOffset(0)) {
public static void extractStyleURLs(final URL baseUrl, final URLCollection urls, String styleTagStr) { Perl5Matcher matcher = JMeterUtils.getMatcher(); Pattern pattern = JMeterUtils.getPatternCache().getPattern( "URL\\(\\s*('|\")(.*)('|\")\\s*\\)", // $NON-NLS-1$ Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK | Perl5Compiler.READ_ONLY_MASK); PatternMatcherInput input = null; input = new PatternMatcherInput(styleTagStr); while (matcher.contains(input, pattern)) { MatchResult match = matcher.getMatch(); // The value is in the second group String styleUrl = match.group(2); urls.addURL(styleUrl, baseUrl); } } }