private String getError (String line) { Pattern pattern = Pattern.compile(":[0-9]+:[0-9]+:(.+)"); Matcher matcher = pattern.matcher(line); matcher.find(); return matcher.groupCount() >= 1 ? matcher.group(1).trim() : null; }
private String[] extractArguments(Matcher matcher) { String[] args = new String[matcher.groupCount()]; for (int i = 1; i <= matcher.groupCount(); i++) { args[i - 1] = matcher.group(i); } return args; }
/** * Return the count of groups in the argument. * @param p pattern whose groups to count * @return the count of groups in the argument */ @SuppressWarnings("purity") // does not depend on object identity /*@Pure*/ private static int getGroupCount(Pattern p) { return p.matcher("").groupCount(); } }
/** * @param fileName Sting version of path to validate. * @return True if the file name has format of a del file. */ public static boolean isDelFile(final String fileName) { Matcher m = DELFILE_NAME_PATTERN.matcher(fileName); return m.matches() && m.groupCount() > 0; }
@Override public void configure(Context context) { String regexString = context.getString(REGEX); Preconditions.checkArgument(!StringUtils.isEmpty(regexString), "Must supply a valid regex string"); regex = Pattern.compile(regexString); regex.pattern(); regex.matcher("").groupCount(); configureSerializers(context); }
@Override protected Result[] run(String value) { final Matcher matcher = pattern.matcher(value); if (!matcher.find() || matcher.groupCount() == 0 || matcher.start(1) == -1 || matcher.end(1) == -1) { return null; } return new Result[] { new Result(value.substring(matcher.start(1), matcher.end(1)), matcher.start(1), matcher.end(1)) }; }
Matcher m = responseCodePattern.matcher(firstHeader); m.matches(); m.groupCount(); m.group(0); //must call matches() first ...
private int getLineNumber (String line) { Pattern pattern = Pattern.compile(":([0-9]+):[0-9]+:"); Matcher matcher = pattern.matcher(line); matcher.find(); return matcher.groupCount() >= 1 ? Integer.parseInt(matcher.group(1)) : -1; } });
/** * @param name file name to check. * @return True if the path has format of a HStoreFile reference. */ public static boolean isReference(final String name) { Matcher m = REF_NAME_PATTERN.matcher(name); return m.matches() && m.groupCount() > 1; }
public RegexReplace(final byte[] buffer, final ProcessContext context) { this.buffer = buffer; final String regexValue = context.getProperty(SEARCH_VALUE).evaluateAttributeExpressions().getValue(); numCapturingGroups = Pattern.compile(regexValue).matcher("").groupCount(); additionalAttrs = new HashMap<>(numCapturingGroups); }
public Result runExtractor(String value) { final Matcher matcher = pattern.matcher(value); final boolean found = matcher.find(); if (!found) { return null; } final int start = matcher.groupCount() > 0 ? matcher.start(1) : -1; final int end = matcher.groupCount() > 0 ? matcher.end(1) : -1; final String s; try { s = replaceAll ? matcher.replaceAll(replacement) : matcher.replaceFirst(replacement); } catch (Exception e) { throw new RuntimeException("Error while trying to replace string", e); } return new Result(s, start, end); }
/** * Create a RegexSelector. When there is no capture group, the value is set to 0 else set to 1. * @param regexStr */ public RegexSelector(String regexStr) { this.compileRegex(regexStr); if (regex.matcher("").groupCount() == 0) { this.group = 0; } else { this.group = 1; } }
private String contentsOfFirstGroupThatMatched(Matcher matcher) { for (int i = 1; i <= matcher.groupCount(); i++) { String groupContent = matcher.group(i); if (groupContent != null) { return groupContent; } } return null; }
private String getError (String line) { Pattern pattern = Pattern.compile(":[0-9]+:[0-9]+:(.+)"); Matcher matcher = pattern.matcher(line); matcher.find(); return matcher.groupCount() >= 1 ? matcher.group(1).trim() : null; }
public static boolean isHFile(final String fileName) { Matcher m = HFILE_NAME_PATTERN.matcher(fileName); return m.matches() && m.groupCount() > 0; }
private ReplaceTextCallback(ProcessContext context, FlowFile flowFile, int maxBufferSize) { this.regex = context.getProperty(REGEX).evaluateAttributeExpressions(flowFile, quotedAttributeDecorator).getValue(); this.flowFile = flowFile; this.charset = Charset.forName(context.getProperty(CHARACTER_SET).getValue()); final String regexValue = context.getProperty(REGEX).evaluateAttributeExpressions().getValue(); this.numCapturingGroups = Pattern.compile(regexValue).matcher("").groupCount(); this.buffer = new byte[maxBufferSize]; this.groupToMatch = context.getProperty(MATCHING_GROUP_FOR_LOOKUP_KEY).evaluateAttributeExpressions().asInteger(); }
/** * Get the starting point for the limit handler to begin injecting and transforming the SQL. * For non-CTE queries, this is offset 0. For CTE queries, this will be where the CTE's * SELECT clause begins (skipping all query definitions, column definitions and expressions). * * This method also sets {@code isCTE} if the query is parsed as a CTE query. * * @param sql The sql buffer. * @return the index where to begin parsing. */ private int getStatementIndex(StringBuilder sql) { final Matcher matcher = WITH_CTE.matcher( sql.toString() ); if ( matcher.find() && matcher.groupCount() > 0 ) { isCTE = true; return locateQueryInCTEStatement( sql, matcher.end() ); } return 0; }
private String contentsOfFirstGroupThatMatched(Matcher matcher) { for (int i = 1; i <= matcher.groupCount(); i++) { String groupContent = matcher.group(i); if (groupContent != null) { return groupContent; } } return null; }
private int getLineNumber (String line) { Pattern pattern = Pattern.compile(":([0-9]+):[0-9]+:"); Matcher matcher = pattern.matcher(line); matcher.find(); return matcher.groupCount() >= 1 ? Integer.parseInt(matcher.group(1)) : -1; } });
String apply(String distinguishedName) { if (isDefault) { return distinguishedName; } String result = null; final Matcher m = pattern.matcher(distinguishedName); if (m.matches()) { result = distinguishedName.replaceAll(pattern.pattern(), escapeLiteralBackReferences(replacement, m.groupCount())); } if (toLowerCase && result != null) { result = result.toLowerCase(Locale.ENGLISH); } else if (toUpperCase & result != null) { result = result.toUpperCase(Locale.ENGLISH); } return result; }