private static DdlResult parseTableName(String matchString, String schmeaName) { Perl5Matcher tableMatcher = new Perl5Matcher(); matchString = matchString + " "; if (tableMatcher.matches(matchString, PatternUtils.getPattern(TABLE_PATTERN))) { String tableString = tableMatcher.getMatch().group(3); if (StringUtils.isEmpty(tableString)) { return null; } tableString = StringUtils.removeEnd(tableString, ";"); tableString = StringUtils.removeEnd(tableString, "("); tableString = StringUtils.trim(tableString); // 特殊处理引号` tableString = removeEscape(tableString); // 处理schema.table的写法 String names[] = StringUtils.split(tableString, "."); if (names.length == 0) { return null; } if (names != null && names.length > 1) { return new DdlResult(removeEscape(names[0]), removeEscape(names[1])); } else { return new DdlResult(schmeaName, removeEscape(names[0])); } } return null; }
private static DdlResult parseDdl(String queryString, String schmeaName, String pattern, int index) { Perl5Matcher matcher = new Perl5Matcher(); if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) { DdlResult result = parseTableName(matcher.getMatch().group(index), schmeaName); return result != null ? result : new DdlResult(schmeaName); // 无法解析时,直接返回schmea,进行兼容处理 } return null; }
private static DdlResult parseRename(String queryString, String schmeaName, String pattern) { Perl5Matcher matcher = new Perl5Matcher(); if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) { DdlResult orign = parseTableName(matcher.getMatch().group(1), schmeaName); DdlResult target = parseTableName(matcher.getMatch().group(2), schmeaName); if (orign != null && target != null) { return new DdlResult(target.getSchemaName(), target.getTableName(), orign.getSchemaName(), orign.getTableName()); } } return null; }
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; }
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; }
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(); }
/** * Returns a Vector of matched groups found in the argument. * * <p>Group 0 will be the full match, the rest are the * parenthesized subexpressions</p>. * * @param input the string to match against * @param options the regex options to use * @return the vector of groups * @throws BuildException on error */ @Override public Vector<String> getGroups(final String input, final int options) throws BuildException { if (!matches(input, options)) { return null; } final Vector<String> v = new Vector<>(); final MatchResult mr = matcher.getMatch(); final int cnt = mr.groups(); for (int i = 0; i < cnt; i++) { String match = mr.group(i); // treat non-matching groups as empty matches if (match == null) { match = ""; } v.add(match); } return v; }
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 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; } } }
MatchResult result = null; if (_preparse_matcher_.matches(entry, _preparse_pattern_)) { result = _preparse_matcher_.getMatch(); String name = result.group(1); String version = result.group(2); MatchResult result = null; if (_preparse_matcher_.matches(entry, _preparse_pattern_)) { result = _preparse_matcher_.getMatch(); String name = result.group(1); String version = result.group(2);
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 }
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); }
MatchResult match = matcher.getMatch(); Map parameters = new HashMap(match.groups()); for (int i = 1; i < match.groups(); i++) {
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; } }
MatchResult result = matcher.getMatch(); if (firstResult == null || result.beginOffset(0) < firstResult.beginOffset(0)) { firstResult = result;
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); } } }