本文整理了Java中java.util.regex.Matcher.groupCount()
方法的一些代码示例,展示了Matcher.groupCount()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matcher.groupCount()
方法的具体详情如下:
包路径:java.util.regex.Matcher
类名称:Matcher
方法名:groupCount
[英]Returns the number of groups in the results, which is always equal to the number of groups in the original regular expression.
[中]返回结果中的组数,它始终等于原始正则表达式中的组数。
代码示例来源:origin: libgdx/libgdx
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;
}
代码示例来源:origin: gocd/gocd
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;
}
代码示例来源:origin: google/j2objc
/**
* 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();
}
}
代码示例来源:origin: apache/hbase
/**
* @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;
}
代码示例来源:origin: apache/flume
@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);
}
代码示例来源:origin: Graylog2/graylog2-server
@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)) };
}
代码示例来源:origin: stackoverflow.com
Matcher m = responseCodePattern.matcher(firstHeader);
m.matches();
m.groupCount();
m.group(0); //must call matches() first
...
代码示例来源:origin: libgdx/libgdx
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;
}
});
代码示例来源:origin: apache/hbase
/**
* @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;
}
代码示例来源:origin: apache/nifi
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);
}
代码示例来源:origin: Graylog2/graylog2-server
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);
}
代码示例来源:origin: code4craft/webmagic
/**
* 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;
}
}
代码示例来源:origin: gocd/gocd
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;
}
代码示例来源:origin: libgdx/libgdx
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;
}
代码示例来源:origin: apache/hbase
public static boolean isHFile(final String fileName) {
Matcher m = HFILE_NAME_PATTERN.matcher(fileName);
return m.matches() && m.groupCount() > 0;
}
代码示例来源:origin: apache/nifi
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();
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* 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;
}
代码示例来源:origin: gocd/gocd
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;
}
代码示例来源:origin: libgdx/libgdx
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;
}
});
代码示例来源:origin: apache/kafka
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;
}
内容来源于网络,如有侵权,请联系作者删除!