本文整理了Java中java.util.regex.Matcher.matches()
方法的一些代码示例,展示了Matcher.matches()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matcher.matches()
方法的具体详情如下:
包路径:java.util.regex.Matcher
类名称:Matcher
方法名:matches
[英]Tries to match the Pattern against the entire region (or the entire input, if no region has been set).
[中]尝试将模式与整个区域(或整个输入,如果未设置区域)匹配。
代码示例来源:origin: spring-projects/spring-framework
/**
* Returns {@code true} if the exclusion {@link Pattern} at index {@code patternIndex}
* matches the supplied candidate {@code String}.
*/
@Override
protected boolean matchesExclusion(String candidate, int patternIndex) {
Matcher matcher = this.compiledExclusionPatterns[patternIndex].matcher(candidate);
return matcher.matches();
}
代码示例来源:origin: apache/kafka
/**
* Extracts the hostname from a "host:port" address string.
* @param address address string to parse
* @return hostname or null if the given address is incorrect
*/
public static String getHost(String address) {
Matcher matcher = HOST_PORT_PATTERN.matcher(address);
return matcher.matches() ? matcher.group(1) : null;
}
代码示例来源:origin: org.mockito/mockito-core
static boolean isJava8BelowUpdate45(String jvmVersion) {
Matcher matcher = JAVA_8_RELEASE_VERSION_SCHEME.matcher(jvmVersion);
if (matcher.matches()) {
int update = Integer.parseInt(matcher.group(1));
return update < 45;
}
matcher = JAVA_8_DEV_VERSION_SCHEME.matcher(jvmVersion);
if (matcher.matches()) {
int update = Integer.parseInt(matcher.group(1));
return update < 45;
}
matcher = Pattern.compile("1\\.8\\.0-b\\d+").matcher(jvmVersion);
return matcher.matches();
}
代码示例来源:origin: jersey/jersey
@Override
public boolean processLine(final String line) throws IOException {
if (PATTERN.matcher(line).matches()) {
matchedLines.add(line);
}
return true;
}
代码示例来源:origin: neo4j/neo4j
static List<File> matchingFiles( File fileWithRegexInName )
{
File parent = fileWithRegexInName.getAbsoluteFile().getParentFile();
if ( parent == null || !parent.exists() )
{
throw new IllegalArgumentException( "Directory of " + fileWithRegexInName + " doesn't exist" );
}
final Pattern pattern = Pattern.compile( fileWithRegexInName.getName() );
List<File> files = new ArrayList<>();
for ( File file : parent.listFiles() )
{
if ( pattern.matcher( file.getName() ).matches() )
{
files.add( file );
}
}
return files;
}
代码示例来源:origin: stanfordnlp/CoreNLP
public void bindStringRegex(String var, String regex)
{
// Enforce requirements on variable names ($alphanumeric_)
if (!STRING_REGEX_VAR_NAME_PATTERN.matcher(var).matches()) {
throw new IllegalArgumentException("StringRegex binding error: Invalid variable name " + var);
}
Pattern varPattern = Pattern.compile(Pattern.quote(var));
String replace = Matcher.quoteReplacement(regex);
stringRegexVariables.put(var, new Pair<>(varPattern, replace));
}
代码示例来源:origin: jenkinsci/jenkins
/**
* See {@link hudson.FilePath#isAbsolute(String)}.
* @param path String representing <code> Platform Specific </code> (unlike FilePath, which may get Platform agnostic paths), may not be null
* @return true if String represents absolute path on this platform, false otherwise
*/
public static boolean isAbsolute(String path) {
Pattern DRIVE_PATTERN = Pattern.compile("[A-Za-z]:[\\\\/].*");
return path.startsWith("/") || DRIVE_PATTERN.matcher(path).matches();
}
代码示例来源:origin: org.testng/testng
private static Boolean isMatch(Pattern pattern, String group) {
Pair<String, String> cacheKey = Pair.create(pattern.pattern(), group);
Boolean match = MATCH_CACHE.get(cacheKey);
if (match == null) {
match = pattern.matcher(group).matches();
MATCH_CACHE.put(cacheKey, match);
}
return match;
}
代码示例来源:origin: jenkinsci/jenkins
public void execute(TaskListener listener) {
int numFiles = 0;
File root = new File(getRootDir(), FINGERPRINTS_DIR_NAME);
File[] files1 = root.listFiles(f -> f.isDirectory() && f.getName().length()==2);
if(files1!=null) {
for (File file1 : files1) {
File[] files2 = file1.listFiles(f -> f.isDirectory() && f.getName().length()==2);
for(File file2 : files2) {
File[] files3 = file2.listFiles(f -> f.isFile() && FINGERPRINT_FILE_PATTERN.matcher(f.getName()).matches());
for(File file3 : files3) {
if(check(file3, listener))
numFiles++;
}
deleteIfEmpty(file2);
}
deleteIfEmpty(file1);
}
}
listener.getLogger().println("Cleaned up "+numFiles+" records");
}
代码示例来源:origin: stackoverflow.com
Pattern pattern = Pattern.compile(regex);
System.out.println(pattern.matcher("1").matches());
System.out.println(pattern.matcher("12345").matches());
System.out.println(pattern.matcher("123456789").matches());
代码示例来源:origin: jersey/jersey
@Override
public boolean processLine(final String line) throws IOException {
if (patternCompiled.matcher(line).matches()) {
matchedLines.add(line);
if (maxMatchedLines != 0 && maxMatchedLines <= matchedLines.size()) {
return false;
}
}
return true;
}
代码示例来源:origin: stanfordnlp/CoreNLP
public List<IndexedWord> getAllNodesByPartOfSpeechPattern(String pattern) {
Pattern p = Pattern.compile(pattern);
List<IndexedWord> nodes = new ArrayList<>();
for (IndexedWord vertex : vertexSet()) {
String pos = vertex.tag();
if ((pos == null && pattern == null) || pos != null && p.matcher(pos).matches()) {
nodes.add(vertex);
}
}
return nodes;
}
代码示例来源:origin: apache/kafka
/**
* Extracts the port number from a "host:port" address string.
* @param address address string to parse
* @return port number or null if the given address is incorrect
*/
public static Integer getPort(String address) {
Matcher matcher = HOST_PORT_PATTERN.matcher(address);
return matcher.matches() ? Integer.parseInt(matcher.group(2)) : null;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Returns {@code true} if the {@link Pattern} at index {@code patternIndex}
* matches the supplied candidate {@code String}.
*/
@Override
protected boolean matches(String pattern, int patternIndex) {
Matcher matcher = this.compiledPatterns[patternIndex].matcher(pattern);
return matcher.matches();
}
代码示例来源:origin: libgdx/libgdx
/**
* @return {@code true} if application runs on a mobile device
*/
public static boolean isMobileDevice() {
// RegEx pattern from detectmobilebrowsers.com (public domain)
String pattern = "(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec" +
"|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)" +
"i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)" +
"|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(Window.Navigator.getUserAgent().toLowerCase());
return m.matches();
}
代码示例来源:origin: redisson/redisson
private List<String> getDispatcherNames(Properties configuration) {
List<String> dispatcherNames = new ArrayList<String>();
for (Object propertyName : configuration.keySet()) {
Matcher matcher = REACTOR_NAME_PATTERN.matcher((String) propertyName);
if (matcher.matches()) {
dispatcherNames.add(matcher.group(1));
}
}
return dispatcherNames;
}
代码示例来源:origin: stanfordnlp/CoreNLP
private static String[] splitTokenize(Pattern splitRegexp, Pattern ignoreRegexp, String cWord) {
String[] bits = splitRegexp.split(cWord);
if (ignoreRegexp != null) {
List<String> keepBits = new ArrayList<>(bits.length);
for (String bit : bits) {
if ( ! ignoreRegexp.matcher(bit).matches()) {
keepBits.add(bit);
}
}
if (keepBits.size() != bits.length) {
bits = new String[keepBits.size()];
keepBits.toArray(bits);
}
}
return bits;
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Returns all nodes of type {@link edu.stanford.nlp.ling.IndexedWord
* IndexedWord} in this {@code SemanticGraph} having the given word or
* regex, or returns empty list if no such found.
*/
public List<IndexedWord> getAllNodesByWordPattern(String pattern) {
Pattern p = Pattern.compile(pattern);
List<IndexedWord> nodes = new ArrayList<>();
for (IndexedWord vertex : vertexSet()) {
String w = vertex.word();
if ((w == null && pattern == null) || w != null && p.matcher(w).matches()) {
nodes.add(vertex);
}
}
return nodes;
}
代码示例来源:origin: Netflix/eureka
public static String extractZoneFromHostName(String hostName) {
Matcher matcher = ZONE_RE.matcher(hostName);
if (matcher.matches()) {
return matcher.group(2);
}
return null;
}
代码示例来源:origin: square/okhttp
/** Returns true if {@code host} is not a host name and might be an IP address. */
public static boolean verifyAsIpAddress(String host) {
return VERIFY_AS_IP_ADDRESS.matcher(host).matches();
}
内容来源于网络,如有侵权,请联系作者删除!