本文整理汇总了Java中java.util.regex.MatchResult.groupCount方法的典型用法代码示例。如果您正苦于以下问题:Java MatchResult.groupCount方法的具体用法?Java MatchResult.groupCount怎么用?Java MatchResult.groupCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.regex.MatchResult
的用法示例。
在下文中一共展示了MatchResult.groupCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setProxy
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* Define the proxy to use for all GA tracking requests.
* <p>
* Call this static method early (before creating any tracking requests).
*
* @param proxyAddr
* "addr:port" of the proxy to use; may also be given as URL
* ("http://addr:port/").
*/
public static void setProxy(String proxyAddr)
{
if(proxyAddr != null)
{
Scanner s = new Scanner(proxyAddr);
// Split into "proxyAddr:proxyPort".
proxyAddr = null;
int proxyPort = 8080;
try
{
s.findInLine("(http://|)([^:/]+)(:|)([0-9]*)(/|)");
MatchResult m = s.match();
if(m.groupCount() >= 2)
proxyAddr = m.group(2);
if(m.groupCount() >= 4 && !(m.group(4).length() == 0))
proxyPort = Integer.parseInt(m.group(4));
}finally
{
s.close();
}
if(proxyAddr != null)
{
SocketAddress sa = new InetSocketAddress(proxyAddr, proxyPort);
setProxy(new Proxy(Type.HTTP, sa));
}
}
}
示例2: parseName
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* 根据文件名得到插件名
*
* @param fullname
* @param type
* @return
*/
public static final String parseName(String fullname, int type) {
Matcher m = null;
if (type == INCREMENT_PLUGIN) {
m = INCREMENT_REGEX.matcher(fullname);
} else if (type == SINGLE_PLUGIN) {
m = INCREMENT_SINGLE_REGEX.matcher(fullname);
} else if (type == MULTI_PLUGIN) {
m = MULTI_REGEX.matcher(fullname);
} else {
m = NORMAL_REGEX.matcher(fullname);
}
if (m == null || !m.matches()) {
return null;
}
MatchResult r = m.toMatchResult();
if (r == null || r.groupCount() != 1) {
return null;
}
return r.group(1);
}
示例3: parseMonitorInfo
import java.util.regex.MatchResult; //导入方法依赖的package包/类
private MonitorInfo parseMonitorInfo(String line, String pattern) {
Scanner s = new Scanner(line);
s.findInLine(pattern);
MonitorInfo mi = new MonitorInfo();
MatchResult res = s.match();
mi.setType(res.group(1));
mi.setMonitorAddress(res.group(2));
if (res.groupCount() > 2) {
mi.setMonitorClass(res.group(3));
}
return mi;
}
示例4: get
import java.util.regex.MatchResult; //导入方法依赖的package包/类
@Override
protected String[] get(Event e) {
List<MatchResult> regexes = ((CustomSyntaxEvent) e).getParseResult().regexes;
if (index < regexes.size()) {
MatchResult match = regexes.get(index);
int groupCount = match.groupCount();
String[] groups = new String[groupCount];
for (int i = 1; i <= groupCount; i++) {
groups[i - 1] = match.group(i);
}
return groups;
}
return new String[0];
}
示例5: RegexMatchResult
import java.util.regex.MatchResult; //导入方法依赖的package包/类
public RegexMatchResult(boolean matches, MatchResult matchResult, List<String> groupNames) {
this.matches = matches;
ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder();
if (matches) {
// arggggh! not 0 based.
final int groupCount = matchResult.groupCount();
for (int i = 1; i <= groupCount; i++) {
final String groupValue = matchResult.group(i);
if (groupValue == null) {
// You cannot add null values to an ImmutableMap but optional matcher groups may be null.
continue;
}
// try to get a group name, if that fails use a 0-based index as the name
final String groupName = Iterables.get(groupNames, i - 1, null);
builder.put(groupName != null ? groupName : String.valueOf(i - 1), groupValue);
}
}
groups = builder.build();
}
示例6: setProxy
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* Define the proxy to use for all GA tracking requests.
* <p>
* Call this static method early (before creating any tracking requests).
*
* @param proxyAddr
* "addr:port" of the proxy to use; may also be given as URL
* ("http://addr:port/").
*/
public static void setProxy(String proxyAddr) {
if (proxyAddr != null) {
String oldProxyAddr = proxyAddr;
// Split into "proxyAddr:proxyPort".
proxyAddr = null;
int proxyPort = 8080;
try (Scanner s = new Scanner(oldProxyAddr)) {
s.findInLine("(http://|)([^:/]+)(:|)([0-9]*)(/|)");
MatchResult m = s.match();
if (m.groupCount() >= 2) proxyAddr = m.group(2);
if (m.groupCount() >= 4 && !(m.group(4).length() == 0)) proxyPort = Integer.parseInt(m.group(4));
}
if (proxyAddr != null) {
SocketAddress sa = new InetSocketAddress(proxyAddr, proxyPort);
setProxy(new Proxy(Type.HTTP, sa));
}
}
}
示例7: parse
import java.util.regex.MatchResult; //导入方法依赖的package包/类
public Map<String,String> parse(String str) {
if ( !matches(str) ) {
throw new IllegalArgumentException(String.format("[%s] doesn't match pattern [%s]", str, m_pattern));
}
Scanner scanner = new Scanner(str);
scanner.findWithinHorizon(m_regex, 0);
MatchResult result = scanner.match();
Map<String,String> vals = new HashMap<String,String>();
if ( result.groupCount()!=m_nameList.size() ) {
// this shouldn't be able to happen
throw new IllegalStateException(String.format("[%s] doesn't match pattern [%s]; found %d matches, expected %d", str, m_pattern, result.groupCount(), m_nameList.size()));
}
for (int i=1; i<=result.groupCount(); i++) {
String name = m_nameList.get(i-1);
String val = result.group(i);
if ( vals.containsKey(name) ) {
if ( !vals.get(name).equals(val) ) {
throw new IllegalArgumentException(String.format("[%s]doesnt match pattern [%s]; variable [%s] has values [%s] and [%s]", str, m_pattern, name, val, vals.get(name)));
}
}
vals.put(name,result.group(i));
}
return vals;
}
示例8: parseVariableName
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* <p>parseVariableName.</p>
*
* @return a {@link java.lang.String} object.
*/
public String parseVariableName() {
if(asString == null)
return null;
String var = asString.trim();
if(!var.startsWith("$"))
throw new IllegalStateException("This expression is not a variable reference");
Scanner scanner = new Scanner(var.substring(1));
scanner.findInLine("\\{\\s*(\\w+)\\s*\\}");
MatchResult matchResults = scanner.match();
if(matchResults.groupCount() != 1)
throw new IllegalStateException("Malformed variable name expression.");
return matchResults.group(1);
}
示例9: setParameterString
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* DocumentFileFactory get two parameters: [dir="filePath"] - path to directory
* which contains set of documents presented by frequence term vector and
* [maxDoc=d+] - the restriction on the number returned documents.
* if you want do not restrict the number of documents set maxDoc=0
* @param param
*/
@Override
public void setParameterString(String param) {
Scanner s = new Scanner(new StringReader(param));
s.findInLine("dir=(.+); maxDoc=(\\d+)");
MatchResult matchResult = s.match();
for (int i=1; i<=matchResult.groupCount(); i++)
System.out.println(matchResult.group(i));
s.close();
testDataDirPath = matchResult.group(1);
maxDoc = Integer.valueOf(matchResult.group(2));
if (maxDoc == 0) maxDoc = Integer.MAX_VALUE;
}
示例10: build
import java.util.regex.MatchResult; //导入方法依赖的package包/类
public static final PluginInfo build(File f) {
Matcher m = REGEX.matcher(f.getName());
if (m == null || !m.matches()) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "PluginInfo.build: skip, no match1, file=" + f.getAbsolutePath());
}
return null;
}
MatchResult r = m.toMatchResult();
if (r == null || r.groupCount() != 4) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "PluginInfo.build: skip, no match2, file=" + f.getAbsolutePath());
}
return null;
}
String name = r.group(1);
int low = Integer.parseInt(r.group(2));
int high = Integer.parseInt(r.group(3));
int ver = Integer.parseInt(r.group(4));
String path = f.getPath();
PluginInfo info = new PluginInfo(name, low, high, ver, TYPE_PN_INSTALLED, DownloadFileInfo.NONE_PLUGIN, path, -1, -1, -1, null);
if (LOG) {
LogDebug.d(PLUGIN_TAG, "PluginInfo.build: found plugin, name=" + info.getName()
+ " low=" + info.getLowInterfaceApi() + " high=" + info.getHighInterfaceApi()
+ " ver=" + info.getVersion());
}
return info;
}
示例11: parse
import java.util.regex.MatchResult; //导入方法依赖的package包/类
@Override
public void parse(String line) {
if (parseLineCount < lineCount) {
// accumulate
parseLine = parseLine + System.getProperty("line.separator") + line;
parseLineCount++;
return;
} else {
if (parseLineCount > 1) {
parseLine = parseLine + System.getProperty("line.separator") + line;
} else {
parseLine = line;
}
}
Matcher lineMatcher = linePattern.matcher(parseLine);
// capture the current one and build the previous one
if (lineMatcher.matches()) {
buildLogEntry();
logEntryText = parseLine;
MatchResult result = lineMatcher.toMatchResult();
for (int i = 1; i < result.groupCount() + 1; i++) {
// String key = logEntryColumnList.get(i - 1);
String value = result.group(i);
logEntryColumnValueList.add(value);
}
} else {
additionalLines.add(parseLine);
}
}
示例12: parseIndexFile
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* Parse the contents of an index file, caching the results internally.
* @param indexFile File to parse.
* @throws FileNotFoundException Thrown if file could not be opened.
*/
private void parseIndexFile(File indexFile) {
try {
Scanner scanner = new Scanner(indexFile);
int sequenceIndex = 0;
while( scanner.hasNext() ) {
// Tokenize and validate the index line.
String result = scanner.findInLine("(.+)\\t+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)");
if( result == null )
throw new PicardException("Found invalid line in index file:" + scanner.nextLine());
MatchResult tokens = scanner.match();
if( tokens.groupCount() != 5 )
throw new PicardException("Found invalid line in index file:" + scanner.nextLine());
// Skip past the line separator
scanner.nextLine();
// Parse the index line.
String contig = tokens.group(1);
long size = Long.valueOf(tokens.group(2));
long location = Long.valueOf(tokens.group(3));
int basesPerLine = Integer.valueOf(tokens.group(4));
int bytesPerLine = Integer.valueOf(tokens.group(5));
contig = SAMSequenceRecord.truncateSequenceName(contig);
// Build sequence structure
add(new FastaSequenceIndexEntry(contig,location,size,basesPerLine,bytesPerLine, sequenceIndex++) );
}
} catch (FileNotFoundException e) {
throw new PicardException("Fasta index file should be found but is not: " + indexFile, e);
}
}
示例13: getCPUBogoMips
import java.util.regex.MatchResult; //导入方法依赖的package包/类
public static float getCPUBogoMips() throws SystemUtilsException {
final MatchResult matchResult = SystemUtils.matchSystemFile("/proc/cpuinfo", SystemUtils.BOGOMIPS_PATTERN, 1000);
try {
if (matchResult.groupCount() > 0) {
return Float.parseFloat(matchResult.group(1));
} else {
throw new SystemUtilsException();
}
} catch (final NumberFormatException e) {
throw new SystemUtilsException(e);
}
}
示例14: getSystemMemoryFreeSize
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* @return in kiloBytes.
* @throws org.andengine.util.system.SystemUtils.SystemUtilsException
*/
public static long getSystemMemoryFreeSize() throws SystemUtilsException {
final MatchResult matchResult = SystemUtils.matchSystemFile("/proc/meminfo", SystemUtils.MEMFREE_PATTERN, 1000);
try {
if (matchResult.groupCount() > 0) {
return Long.parseLong(matchResult.group(1));
} else {
throw new SystemUtilsException();
}
} catch (final NumberFormatException e) {
throw new SystemUtilsException(e);
}
}
示例15: getSystemMemorySize
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* @return in kiloBytes.
* @throws org.andengine.util.system.SystemUtils.SystemUtilsException
*/
public static long getSystemMemorySize() throws SystemUtilsException {
final MatchResult matchResult = SystemUtils.matchSystemFile("/proc/meminfo", SystemUtils.MEMTOTAL_PATTERN, 1000);
try {
if (matchResult.groupCount() > 0) {
return Long.parseLong(matchResult.group(1));
} else {
throw new SystemUtilsException();
}
} catch (final NumberFormatException e) {
throw new SystemUtilsException(e);
}
}