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; }
private static void split(Collection results, PatternMatcher matcher, Pattern pattern, String input, int limit) { int beginOffset; MatchResult currentResult; PatternMatcherInput pinput; pinput = new PatternMatcherInput(input); beginOffset = 0; while (--limit != 0 && matcher.contains(pinput, pattern)) { currentResult = matcher.getMatch(); results.add(input.substring(beginOffset, currentResult .beginOffset(0))); beginOffset = currentResult.endOffset(0); } results.add(input.substring(beginOffset, input.length())); }
/** * 创建一个新的context. * * @param input 要匹配的字符串 */ public void init(String input) { if (this.matcher == null) { this.matcher = createPatternMatcher(); } if (this.input == null) { this.input = new PatternMatcherInput(input); } else { this.input.setInput(input); } }
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; }
/** * Create an <code>Expect4j</code> instance based on an {@link * IOPair} concrete instance. * * @param pair the <code>IOPair</code> concrete instance that * provides access to the reader/writer streams */ public Expect4j(IOPair pair) { logger.trace("Creating new Expect4J instance " + this + " using IOPair " + pair); // Matching matcher = new Perl5Matcher(); matcher.setMultiline(true); input = new PatternMatcherInput(""); // IO this.pair = pair; if (true) { consumer = new BlockingConsumer(pair); } else { // TODO: this section is never hit due to the "if (true)" above consumer = new PollingConsumer(pair); } consumerThread = new Thread(consumer); consumerThread.setDaemon(true); logger.trace("Starting consumer thread " + consumerThread + " for Expect4J instance " + this); consumerThread.start(); mode = STATE_INITIALIZED; }
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(); }
/** * 获取第{matchidx}次的匹配 * @param input * @param regx * @param matchidx * @param groupidx * @return */ public static String getMatch(String input, String regx, int matchidx, int groupidx) { try { Perl5Util perlUtil = getPerlUtil(); PatternMatcherInput patternInput = new PatternMatcherInput(input); while (perlUtil.match(regx, patternInput)) { if (--matchidx < 1){ MatchResult result = perlUtil.getMatch(); return result.group(groupidx); } } } catch (Exception e) { log.error(e.getStackTrace().toString()); } return ""; }
return false; PatternMatcherInput input = new PatternMatcherInput( path ); if ( matcher.contains( input, pattern ) )
PatternMatcher matcher = JMeterUtils.getMatcher(); Util.split(pieces, matcher, templatePattern, rawTemplate); PatternMatcherInput input = new PatternMatcherInput(rawTemplate); boolean startsWith = isFirstElementGroup(rawTemplate); if (startsWith) {
/** *获取所有的匹配项 * @param input * @param regx * @param groupidx * @return */ public static List<String> getAllMatches(String input, String regx, int groupidx) { List<String> matches = new ArrayList<String>(); try { Perl5Util perlUtil = getPerlUtil(); PatternMatcherInput patternInput = new PatternMatcherInput(input); while (perlUtil.match(regx, patternInput)) { MatchResult result = perlUtil.getMatch(); if (result.groups() > groupidx) { matches.add(result.group(groupidx)); } else { matches.add(result.group(0)); } } } catch (Exception e) { log.error(e.getStackTrace().toString()); } return matches; }
PatternMatcherInput pinput = new PatternMatcherInput(rawTemplate); while(matcher.contains(pinput, templatePattern)) { currentResult = matcher.getMatch();
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); } }
String[] tokens = null; List<String> sets = new ArrayList<String>(); PatternMatcherInput input = new PatternMatcherInput(src);
String[] tokens = null; List sets = new ArrayList(); PatternMatcherInput input = new PatternMatcherInput(src);
String[] tokens = null; List<String> sets = new ArrayList<String>(); PatternMatcherInput input = new PatternMatcherInput(src);
String[] tokens = null; List<String> sets = new ArrayList<String>(); PatternMatcherInput input = new PatternMatcherInput(src);
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; } }
String[] tokens = null; List<String> sets = new ArrayList<String>(); PatternMatcherInput input = new PatternMatcherInput(src);
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); } } }
PatternMatcherInput input = new PatternMatcherInput(headerLine); Pattern pattern = JMeterUtils.getPatternCache()