本文整理汇总了Java中java.util.regex.MatchResult类的典型用法代码示例。如果您正苦于以下问题:Java MatchResult类的具体用法?Java MatchResult怎么用?Java MatchResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MatchResult类属于java.util.regex包,在下文中一共展示了MatchResult类的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());
}
示例2: parseThreadInfo
import java.util.regex.MatchResult; //导入依赖的package包/类
protected ThreadStack parseThreadInfo(String threadInfo) {
Scanner s = new Scanner(threadInfo);
ThreadStack result = new ThreadStack();
// parsing thread info
s.findInLine(threadInfoPattern());
MatchResult res = s.match();
result.setThreadName(res.group(1));
result.setType(res.group(3));
result.setPriority(res.group(4));
result.setTid(res.group(7));
result.setNid(res.group(8));
result.setStatus(res.group(9));
s.close();
return result;
}
示例3: 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;
}
示例4: setWinCeVersion
import java.util.regex.MatchResult; //导入依赖的package包/类
private void setWinCeVersion(OperatingSystem model) {
//TODO: to be refined
String osV = model.getVersion();
if (osV == null) {
return;
} else if (!model.getMajorRevision().equals("1")) {
return;
}
if (osV.matches(".*(\\d+).(\\d+).(\\d+).(\\d+).*")) {
Scanner s = new Scanner(osV);
s.findInLine(".*(\\d+).(\\d+).(\\d+).(\\d+).*");
MatchResult result = s.match();
if (result.group(1).equals("4")) {
model.setMajorRevision("5");
} else if (result.group(1).equals("6")) {
model.setMajorRevision("6");
if (result.group(3).equals("7")) {
model.setMinorRevision("1");
}
}
}
}
示例5: 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));
}
}
}
示例6: 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);
}
示例7: 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;
}
示例8: 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;
}
示例9: findAllFileTest
import java.util.regex.MatchResult; //导入依赖的package包/类
public void findAllFileTest() {
// derive expected result by using conventional loop
Pattern pat = Pattern.compile("[A-Z]{7,}");
List<String> expected = new ArrayList<>();
try (Scanner sc = makeFileScanner(inputFile)) {
String match;
while ((match = sc.findWithinHorizon(pat, 0)) != null) {
expected.add(match);
}
}
Supplier<Stream<String>> ss =
() -> makeFileScanner(inputFile).findAll(pat).map(MatchResult::group);
withData(TestData.Factory.ofSupplier("findAllFileTest", ss))
.stream(LambdaTestHelpers.identity())
.expectedResult(expected)
.exercise();
}
示例10: findAllZeroTest
import java.util.regex.MatchResult; //导入依赖的package包/类
@Test(dataProvider = "FindAllZero")
public void findAllZeroTest(String input, String patternString) {
Pattern pattern = Pattern.compile(patternString);
// generate expected result using Matcher.find()
Matcher m = pattern.matcher(input);
List<String> expected = new ArrayList<>();
while (m.find()) {
expected.add(m.group());
}
Supplier<Stream<String>> ss = () -> new Scanner(input).findAll(pattern)
.limit(100)
.map(MatchResult::group);
withData(TestData.Factory.ofSupplier("findAllZeroTest", ss))
.stream(LambdaTestHelpers.identity())
.expectedResult(expected)
.exercise();
}
示例11: 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());
}
}
}
示例12: 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];
}
示例13: 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());
}
};
}
示例14: findQueryPrefixes
import java.util.regex.MatchResult; //导入依赖的package包/类
/**
* Find all prefixes declared in the query
* @param queryString
* @return
*/
protected static Set<String> findQueryPrefixes(String queryString) {
Set<String> res = new HashSet<String>();
Scanner sc = new Scanner(queryString);
while (true) {
while (sc.findInLine(prefixPattern)!=null) {
MatchResult m = sc.match();
res.add(m.group(1));
}
if (!sc.hasNextLine())
break;
sc.nextLine();
}
sc.close();
return res;
}
示例15: findAllTest
import java.util.regex.MatchResult; //导入依赖的package包/类
public void findAllTest() {
// derive expected result by using conventional loop
Pattern pat = Pattern.compile("[A-Z]{7,}");
List<String> expected = new ArrayList<>();
try (Scanner sc = makeFileScanner(inputFile)) {
String match;
while ((match = sc.findWithinHorizon(pat, 0)) != null) {
expected.add(match);
}
}
Supplier<Stream<String>> ss =
() -> makeFileScanner(inputFile).findAll(pat).map(MatchResult::group);
withData(TestData.Factory.ofSupplier("findAllTest", ss))
.stream(LambdaTestHelpers.identity())
.expectedResult(expected)
.exercise();
}