本文整理了Java中java.util.regex.Matcher.find()
方法的一些代码示例,展示了Matcher.find()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matcher.find()
方法的具体详情如下:
包路径:java.util.regex.Matcher
类名称:Matcher
方法名:find
[英]Returns the next occurrence of the Pattern in the input. If a previous match was successful, the method continues the search from the first character following that match in the input. Otherwise it searches either from the region start (if one has been set), or from position 0.
[中]返回输入中模式的下一个匹配项。如果前一个匹配成功,该方法将从输入中匹配后的第一个字符继续搜索。否则,它将从区域开始(如果已设置)或从位置0进行搜索。
代码示例来源:origin: square/retrofit
/**
* Gets the set of unique path parameters used in the given URI. If a parameter is used twice
* in the URI, it will only show up once in the set.
*/
static Set<String> parsePathParameters(String path) {
Matcher m = PARAM_URL_REGEX.matcher(path);
Set<String> patterns = new LinkedHashSet<>();
while (m.find()) {
patterns.add(m.group(1));
}
return patterns;
}
代码示例来源:origin: stackoverflow.com
String mydata = "some string with 'the data i want' inside";
Pattern pattern = Pattern.compile("'(.*?)'");
Matcher matcher = pattern.matcher(mydata);
if (matcher.find())
{
System.out.println(matcher.group(1));
}
代码示例来源:origin: org.mockito/mockito-core
public boolean matches(String actual) {
return actual != null && Pattern.compile(regex).matcher(actual).find();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Find the first occurrence of the given pattern in this text, or null.
*
* @since 1.349
*/
public MarkupText.SubText findToken(Pattern pattern) {
String text = getText();
Matcher m = pattern.matcher(text);
if(m.find())
return createSubText(m);
return null;
}
代码示例来源:origin: stackoverflow.com
Pattern p = Pattern.compile("^[a-zA-Z]+([0-9]+).*");
Matcher m = p.matcher("Testing123Testing");
if (m.find()) {
System.out.println(m.group(1));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public String extractVersion(String requestPath) {
Matcher matcher = pattern.matcher(requestPath);
if (matcher.find()) {
String match = matcher.group(1);
return (match.contains("-") ? match.substring(match.lastIndexOf('-') + 1) : match);
}
else {
return null;
}
}
代码示例来源:origin: google/guava
/**
* Returns a new {@code MatchResult} that corresponds to a successful match. Apache Harmony (used
* in Android) requires a successful match in order to generate a {@code MatchResult}:
* http://goo.gl/5VQFmC
*/
private static MatchResult newMatchResult() {
Matcher matcher = Pattern.compile(".").matcher("X");
matcher.find();
return matcher.toMatchResult();
}
代码示例来源: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: spring-projects/spring-framework
@Override
@Nullable
public String extractVersion(String requestPath) {
Matcher matcher = pattern.matcher(requestPath);
if (matcher.find()) {
String match = matcher.group(1);
return (match.contains("-") ? match.substring(match.lastIndexOf('-') + 1) : match);
}
else {
return null;
}
}
代码示例来源:origin: google/guava
private static void assertContainsRegex(String expectedRegex, String actual) {
Pattern pattern = Pattern.compile(expectedRegex);
Matcher matcher = pattern.matcher(actual);
if (!matcher.find()) {
String actualDesc = (actual == null) ? "null" : ('<' + actual + '>');
fail("expected to contain regex:<" + expectedRegex + "> but was:" + actualDesc);
}
}
}
代码示例来源: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: spring-projects/spring-framework
/**
* Checks to see if the supplied {@code String} has any placeholders
* that are not specified as constants on this class and throws an
* {@code IllegalArgumentException} if so.
*/
private void checkForInvalidPlaceholders(String message) throws IllegalArgumentException {
Matcher matcher = PATTERN.matcher(message);
while (matcher.find()) {
String match = matcher.group();
if (!ALLOWED_PLACEHOLDERS.contains(match)) {
throw new IllegalArgumentException("Placeholder [" + match + "] is not valid");
}
}
}
代码示例来源:origin: prestodb/presto
private void assertTableProperty(String tableProperties, String key, String regexValue)
{
assertTrue(Pattern.compile(key + "\\s*=\\s*" + regexValue + ",?\\s+").matcher(tableProperties).find(),
"Not found: " + key + " = " + regexValue + " in " + tableProperties);
}
代码示例来源: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: eclipse-vertx/vert.x
public static int parseNdotsOptionFromResolvConf(String s) {
int ndots = -1;
Matcher matcher = NDOTS_OPTIONS_PATTERN.matcher(s);
while (matcher.find()) {
ndots = Integer.parseInt(matcher.group(1));
}
return ndots;
}
代码示例来源: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: androidannotations/androidannotations
public Set<String> extractUrlVariableNames(String uriTemplate) {
Set<String> variableNames = new HashSet<>();
boolean hasValueInAnnotation = uriTemplate != null;
if (hasValueInAnnotation) {
Matcher m = NAMES_PATTERN.matcher(uriTemplate);
while (m.find()) {
variableNames.add(m.group(1));
}
}
return variableNames;
}
代码示例来源:origin: stackoverflow.com
Pattern regex = Pattern.compile("^\\s*User Comments:\\s+(.*)", Pattern.DOTALL);
Matcher regexMatcher = regex.matcher(subjectString);
if (regexMatcher.find()) {
ResultString = regexMatcher.group(1);
}
代码示例来源:origin: commons-io/commons-io
static String getContentTypeEncoding(final String httpContentType) {
String encoding = null;
if (httpContentType != null) {
final int i = httpContentType.indexOf(";");
if (i > -1) {
final String postMime = httpContentType.substring(i + 1);
final Matcher m = CHARSET_PATTERN.matcher(postMime);
encoding = m.find() ? m.group(1) : null;
encoding = encoding != null ? encoding.toUpperCase() : null;
}
}
return encoding;
}
代码示例来源:origin: libgdx/libgdx
private String getFileName (String line) {
Pattern pattern = Pattern.compile("(.*):([0-9])+:[0-9]+:");
Matcher matcher = pattern.matcher(line);
matcher.find();
String fileName = matcher.groupCount() >= 2 ? matcher.group(1).trim() : null;
if (fileName == null) return null;
int index = fileName.indexOf(" ");
if (index != -1)
return fileName.substring(index).trim();
else
return fileName;
}
内容来源于网络,如有侵权,请联系作者删除!