当前位置: 首页>>代码示例>>Java>>正文


Java MatchResult.group方法代码示例

本文整理汇总了Java中java.util.regex.MatchResult.group方法的典型用法代码示例。如果您正苦于以下问题:Java MatchResult.group方法的具体用法?Java MatchResult.group怎么用?Java MatchResult.group使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.regex.MatchResult的用法示例。


在下文中一共展示了MatchResult.group方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseYear

import java.util.regex.MatchResult; //导入方法依赖的package包/类
private int parseYear(Scanner s, int defaultYear) {
    if (s.hasNext(YEAR)) {
        s.next(YEAR);
        MatchResult mr = s.match();
        if (mr.group(1) != null) {
            return 1900;  // systemv has min
        } else if (mr.group(2) != null) {
            return YEAR_MAX_VALUE;
        } else if (mr.group(3) != null) {
            return defaultYear;
        }
        return Integer.parseInt(mr.group(4));
        /*
        if (mr.group("min") != null) {
            //return YEAR_MIN_VALUE;
            return 1900;  // systemv has min
        } else if (mr.group("max") != null) {
            return YEAR_MAX_VALUE;
        } else if (mr.group("only") != null) {
            return defaultYear;
        }
        return Integer.parseInt(mr.group("year"));
        */
    }
    throw new IllegalArgumentException("Unknown year: " + s.next());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:TzdbZoneRulesCompiler.java

示例2: parseMethodInfo

import java.util.regex.MatchResult; //导入方法依赖的package包/类
protected MethodInfo parseMethodInfo(String line) {

        MethodInfo result = new MethodInfo();
        Scanner s = new Scanner(line);

        s.findInLine(methodInfoPattern());
        MatchResult rexp = s.match();
        if (rexp.group(4) != null && rexp.group(4).length() > 0) {
            // line "  at tmtools.jstack.share.utils.Utils.sleep(Utils.java:29)"
            result.setName(rexp.group(1));
            result.setCompilationUnit(rexp.group(2));
            result.setLine(rexp.group(4));

        } else {
            // line "  at java.lang.Thread.sleep(Native Method)"
            result.setName(rexp.group(1));
        }

        s.close();
        return result;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:DefaultFormat.java

示例3: 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));
		}
	}
}
 
开发者ID:Wurst-Imperium,项目名称:Wurst-MC-1.12,代码行数:41,代码来源:JGoogleAnalyticsTracker.java

示例4: 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);
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:28,代码来源:DownloadFileInfo.java

示例5: parseLockInfo

import java.util.regex.MatchResult; //导入方法依赖的package包/类
protected LockInfo parseLockInfo(String line) {
    LockInfo res = new LockInfo();

    Scanner s = new Scanner(line);
    s.findInLine(ownableSynchronizersPattern());

    MatchResult matchRes = s.match();
    String lock = matchRes.group(1).equals("None") ? matchRes.group(1) : matchRes.group(2);
    res.setLock(lock);

    return res;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:DefaultFormat.java

示例6: main

import java.util.regex.MatchResult; //导入方法依赖的package包/类
public static void main(String[] args) {
    String string = "Vol. 15 xxx";
    Pattern p = Pattern.compile(".*(\\d+).*");
    Matcher m = p.matcher(string);

    if (m.find()) {
        MatchResult mr = m.toMatchResult();
        String value = mr.group(1);
        System.out.println("found: " + value);
    }

    p = Pattern.compile("\\d+");
    m = p.matcher(string);
    while (m.find()) {
        try {
            String sub = string.substring(m.start(), m.end());
            System.out.println("found 2: " + sub);
        } catch (NumberFormatException e) {
            logger.error(e.getMessage());
        }
    }
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:23,代码来源:MetadataHelper.java

示例7: 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];
}
 
开发者ID:btk5h,项目名称:skript-mirror,代码行数:17,代码来源:ExprParseRegex.java

示例8: getCreator

import java.util.regex.MatchResult; //导入方法依赖的package包/类
public static TokenCreator getCreator() {
    return new TokenCreator() {

        @Override
        public Pattern getPattern() {
            return EXP;
        }

        @Override
        public Token create(MatchResult matchResult, String source, int line) {
            return new Token.Variable(matchResult.group(),
                    matchResult.group(1), "|def" + matchResult.group(2),
                    source, line, matchResult.start());
        }
    };
}
 
开发者ID:h34tnet,项目名称:temporize,代码行数:17,代码来源:TokenCreator.java

示例9: 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();
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:23,代码来源:RegexMatch.java

示例10: path

import java.util.regex.MatchResult; //导入方法依赖的package包/类
private String path(Object[] args) {
	StringBuffer builder = new StringBuffer();

	Matcher matcher = DynamicParameterMatcher.matches(path);

	while (matcher.find()) {
		MatchResult match = matcher.toMatchResult();

		String name = match.group(1);

		parameters.find(name)
			.filter(p -> p.path())
				.ifPresent(p -> matcher.appendReplacement(builder,
						Optional.ofNullable(args[p.position()]).map(a -> p.resolve(a))
							.orElseThrow(() -> new IllegalArgumentException("Your path argument [" + name + "] cannot be null."))));
	}

	matcher.appendTail(builder);

	return builder.toString();
}
 
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:22,代码来源:EndpointPathParameterResolver.java

示例11: checkPosConstraint

import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
 * Check whether the part of speech constraint defined in a rule is satisfied.
 * @param s
 * @param posConstraint
 * @param m
 * @param jcas
 * @return
 */
public boolean checkPosConstraint(Sentence s, String posConstraint, MatchResult m, JCas jcas) {
	Pattern paConstraint = Pattern.compile("group\\(([0-9]+)\\):(.*?):");
	for (MatchResult mr : Toolbox.findMatches(paConstraint,posConstraint)) {
		int groupNumber = Integer.parseInt(mr.group(1));
		int tokenBegin = s.getBegin() + m.start(groupNumber);
		int tokenEnd   = s.getBegin() + m.end(groupNumber);
		String pos = mr.group(2);
		String pos_as_is = getPosFromMatchResult(tokenBegin, tokenEnd ,s, jcas);
		if (pos_as_is.matches(pos)) {
			Logger.printDetail("POS CONSTRAINT IS VALID: pos should be "+pos+" and is "+pos_as_is);
		} else {
			return false;
		}
	}
	return true;
}
 
开发者ID:tudarmstadt-lt,项目名称:newsleak-frontend,代码行数:25,代码来源:HeidelTimeOpenNLP.java

示例12: 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));
        }
    }
}
 
开发者ID:null-dev,项目名称:EvenWurse,代码行数:32,代码来源:JGoogleAnalyticsTracker.java

示例13: 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);
}
 
开发者ID:strator-dev,项目名称:greenpepper,代码行数:22,代码来源:Expression.java

示例14: parse

import java.util.regex.MatchResult; //导入方法依赖的package包/类
private void parse(String generatorSpec) {
    Matcher m = scopeAndSpec.matcher(generatorSpec);
    if (!m.matches()) {
        throw new RuntimeException("Unable to match generator spec with pattern: " + scopeAndSpec.pattern() + ", generator spec: " + generatorSpec);
    }
    MatchResult matchResult = m.toMatchResult();

    String genscope = matchResult.group(2);
    String genspec = matchResult.group(3);
    logger.trace("genscope:" + genscope + ", genspec" + genspec);

    if (matchResult.group(2) == null) {
        this.runtimeScope = defaultScope;
    } else {
        this.runtimeScope = RuntimeScope.valueOf(genscope);
    }

    this.generatorSpec = genspec;

}
 
开发者ID:jshook,项目名称:testclient,代码行数:21,代码来源:ScopedGeneratorCache.java

示例15: hasNextLine

import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
 * Returns true if there is another line in the input of this scanner.
 * This method may block while waiting for input. The scanner does not
 * advance past any input.
 *
 * @return true if and only if this scanner has another line of input
 * @throws IllegalStateException if this scanner is closed
 */
public boolean hasNextLine() {
    saveState();

    String result = findWithinHorizon(linePattern(), 0);
    if (result != null) {
        MatchResult mr = this.match();
        String lineSep = mr.group(1);
        if (lineSep != null) {
            result = result.substring(0, result.length() -
                                      lineSep.length());
            cacheResult(result);

        } else {
            cacheResult();
        }
    }
    revertState();
    return (result != null);
}
 
开发者ID:zhihan,项目名称:janala2-gradle,代码行数:28,代码来源:Scanner.java


注:本文中的java.util.regex.MatchResult.group方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。