本文整理匯總了Java中java.util.regex.Pattern.matcher方法的典型用法代碼示例。如果您正苦於以下問題:Java Pattern.matcher方法的具體用法?Java Pattern.matcher怎麽用?Java Pattern.matcher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.regex.Pattern
的用法示例。
在下文中一共展示了Pattern.matcher方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convertHow
import java.util.regex.Pattern; //導入方法依賴的package包/類
private String convertHow(String type) {
Matcher matcher;
for (CoTTypeDef cd : this.coTTypeMap) {
if (!cd.isPredicate()) {
Pattern pattern = Pattern.compile(cd.getKey());
matcher = pattern.matcher(type);
if (matcher.find()) {
return this
.filterOutDots(appendToHow(type) + cd.getValue());
}
}
}
// no match was found
return "";
}
示例2: parse
import java.util.regex.Pattern; //導入方法依賴的package包/類
@Override
default RmOutput parse(final String output) {
final RmOutputBuilder rmOutputBuilder = RmOutput.builder();
// when removing a prepared pod, there is an additional line in output like:
// moving expired prepared pod "290710d1-0547-4343-8823-e36a27f8b95c" to garbage
final Set<String> removed = Sets.newHashSet();
final Pattern removedPattern = Pattern.compile("\"(.+)\"");
final Matcher removedMatcher = removedPattern.matcher(output);
while (removedMatcher.find()) {
removed.add(removedMatcher.group(1));
}
rmOutputBuilder.removed(removed.iterator());
return rmOutputBuilder.build();
}
示例3: isEmailValid
import java.util.regex.Pattern; //導入方法依賴的package包/類
public static boolean isEmailValid(String email){
if (email!=null && !email.equals("")) {
String regex = "^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
return true;
}
示例4: getGroupWithRegularExpression
import java.util.regex.Pattern; //導入方法依賴的package包/類
/**
* @param origin
* @param patternStr
* @return The resulting {@code String}
*/
public static String getGroupWithRegularExpression(String origin, String patternStr) {
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(origin);
while (matcher.find()) {
return matcher.group(0);
}
return null;
}
示例5: checkBinaryResource
import java.util.regex.Pattern; //導入方法依賴的package包/類
@Override
public void checkBinaryResource(ResourceContext context) {
String filename = context.file.getName();
if (filename.contains(IGNORE_IMAGE_NIGHT_PNG)) {
return;
}
if (filename.contains(CHECK_IMAGE_WEBP) || filename.contains(CHECK_IMAGE_PNG) || filename.contains(CHECK_IMAGE_JPEG) || filename.contains(CHECK_IMAGE_JPG)) {
String filePath = context.file.getPath();
String pattern = ".*?[mipmap|drawable]\\-(x*)hdpi.*?";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(filePath);
if (m.find()) {
double multiple = 1.5;
if (m.group(1).length() > 0) {
multiple = m.group(1).length() + 1;
}
try {
BufferedImage targetImage = ImageIO.read(context.file);
int width = targetImage.getWidth();
int height = targetImage.getHeight();
if (width % multiple != 0 || height % multiple != 0) {
Location fileLocation = Location.create(context.file);
context.report(ISSUE_IMAGE_SIZE, fileLocation, filePath + " 為" + trimZeroAndDot(multiple) + "倍圖,其寬高應該是" + trimZeroAndDot(multiple) + "的倍數,目前寬高為 (" + width + ", " + height + ")。");
}
} catch (Exception ignored) {
}
}
}
}
示例6: getDocumentDbKey
import java.util.regex.Pattern; //導入方法依賴的package包/類
public String getDocumentDbKey() {
Pattern pattern = Pattern.compile(".*AccountKey=(.*);");
Matcher matcher = pattern.matcher(this.getDocumentDbConnString());
if (matcher.find()) {
return matcher.group(1);
} else {
log.error("DocumentDb AccountKey not found (connection string length: {})",
this.getDocumentDbConnString().length());
return "";
}
}
示例7: getBoundaryStr
import java.util.regex.Pattern; //導入方法依賴的package包/類
/**
* バウンダリ文字列を取得する.
* @param contentType Content-Typeの値
* @return バウンダリ文字列
*/
private String getBoundaryStr(String contentType) {
String boundary = null;
Pattern pattern = Pattern.compile(".+boundary=(.+)");
Matcher m = pattern.matcher(contentType);
// バウンダリの指定が無い
if (!m.matches()) {
throw PersoniumCoreException.OData.BATCH_BODY_FORMAT_HEADER_ERROR.params(HttpHeaders.CONTENT_TYPE);
}
boundary = m.replaceAll("$1");
return boundary;
}
示例8: main
import java.util.regex.Pattern; //導入方法依賴的package包/類
public static void main(String arg[]) {
// A simple speed test for this filter.
final int rep = Integer.parseInt(arg[0]);
final long times = Long.parseLong(arg[1]);
Pattern p = Pattern.compile(".*/(.*/)\\1{" + (rep - 1) + ",}.*");
Matcher m;
//String url = "http://example.com/test/foo/bar/foo/bar/foo/mu/foo/bar/foo/bar/foo/bar/";
//String url = "http://example.com/test/foo/bar1/foo/bar2/foo/mu/foo/bar3/foo/bar4/foo/bar5/test/";
String uri = "http://example.com/test/foo/bar1/foo/bar2/foo/mu/foo/bar3/foo/bar4/foo/bar5/test/foo/bar1/foo/bar2/foo/mu/foo/bar3/foo/bar4/foo/bar5/test/";
DuplicateSegmentsLessThan filter = new DuplicateSegmentsLessThan(rep);
URI buri = BURL.parse(uri);
long start;
System.err.println("Regex: " + (! p.matcher(uri).matches()));
System.err.println("Filter: " + filter.apply(buri));
for(int k = 10; k-- != 0;) {
start = -System.currentTimeMillis();
for(long i = times; i-- != 0;) {
m = p.matcher(uri);
m.matches();
}
start += System.currentTimeMillis();
System.err.printf("Regex: %f Kcalls/s\n", Double.valueOf(times / (double)start));
start = -System.currentTimeMillis();
for(long i = times; i-- != 0;) filter.apply(buri);
start += System.currentTimeMillis();
System.err.printf("Filter: %f Kcalls/s\n", Double.valueOf(times / (double)start));
}
}
示例9: matchesFilter
import java.util.regex.Pattern; //導入方法依賴的package包/類
protected boolean matchesFilter(Pattern filter, String fileName, String fullPath, String parentPath) {
if (filter != null) {
int matchWhat;
try {
matchWhat = getParameterAsInt(PARAMETER_FILTERED_STRING);
} catch (UndefinedParameterError e) {
matchWhat = FILTERED_STRING_FILE_NAME;
}
String matchedName = null;
switch (matchWhat) {
case FILTERED_STRING_FILE_NAME:
matchedName = fileName;
break;
case FILTERED_STRING_FILE_PATH:
matchedName = fullPath;
break;
case FILTERED_STRING_PARENT_FOLDER_NAME:
matchedName = parentPath.substring(parentPath.lastIndexOf("/") + 1);
break;
default:
throw new RuntimeException("Illegal parameter value for filtered string");
}
Matcher matcher = filter.matcher(matchedName);
return matcher.matches();
} else {
return true;
}
}
示例10: testStatementComment
import java.util.regex.Pattern; //導入方法依賴的package包/類
public void testStatementComment() throws Exception {
Connection c = getConnectionWithProps("autoGenerateTestcaseScript=true,logger=StandardLogger");
PrintStream oldErr = System.err;
try {
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(bOut);
System.setErr(printStream);
((com.mysql.jdbc.Connection) c).setStatementComment("Hi there");
c.setAutoCommit(false);
c.createStatement().execute("SELECT 1");
c.commit();
c.rollback();
Pattern pattern = Pattern.compile("Hi");
String loggedData = new String(bOut.toByteArray());
Matcher matcher = pattern.matcher(loggedData);
int count = 0;
while (matcher.find()) {
count++;
}
assertEquals(4, count);
} finally {
System.setErr(oldErr);
}
}
示例11: getBuildDirIntellij
import java.util.regex.Pattern; //導入方法依賴的package包/類
private static URL getBuildDirIntellij(final String path) {
final Pattern pattern = Pattern.compile("(.*/out/)((production)|(test))/((classes)|(resources))/?");
final Matcher matcher = pattern.matcher(path);
if (!matcher.matches()) {
return null;
}
final String url = matcher.group(1) + matcher.group(2) + "/[any]";
LOG.trace("{} -> {}", path, url);
try {
return new URL(url);
} catch (final MalformedURLException e) {
throw new TestEEfiException("Failed to build composite java archive URL", e);
}
}
示例12: doFilterRegionServerByName
import java.util.regex.Pattern; //導入方法依賴的package包/類
private Map<String, List<HRegionInfo>> doFilterRegionServerByName(
Map<String, List<HRegionInfo>> fullRsAndRMap) {
Map<String, List<HRegionInfo>> filteredRsAndRMap = null;
if (this.targets != null && this.targets.length > 0) {
filteredRsAndRMap = new HashMap<String, List<HRegionInfo>>();
Pattern pattern = null;
Matcher matcher = null;
boolean regExpFound = false;
for (String rsName : this.targets) {
if (this.useRegExp) {
regExpFound = false;
pattern = Pattern.compile(rsName);
for (Map.Entry<String, List<HRegionInfo>> entry : fullRsAndRMap.entrySet()) {
matcher = pattern.matcher(entry.getKey());
if (matcher.matches()) {
filteredRsAndRMap.put(entry.getKey(), entry.getValue());
regExpFound = true;
}
}
if (!regExpFound) {
LOG.info("No RegionServerInfo found, regionServerPattern:" + rsName);
}
} else {
if (fullRsAndRMap.containsKey(rsName)) {
filteredRsAndRMap.put(rsName, fullRsAndRMap.get(rsName));
} else {
LOG.info("No RegionServerInfo found, regionServerName:" + rsName);
}
}
}
} else {
filteredRsAndRMap = fullRsAndRMap;
}
return filteredRsAndRMap;
}
示例13: getAttributeValue
import java.util.regex.Pattern; //導入方法依賴的package包/類
public String getAttributeValue(String pattern) {
Pattern p = Pattern.compile(pattern);
for (String attr : this.attributes) {
Matcher matcher = p.matcher(attr);
if (matcher.matches()) {
return matcher.group(1);
}
}
return null;
}
示例14: main
import java.util.regex.Pattern; //導入方法依賴的package包/類
public static void main(String args[]) {
String line = "Speed: Unknown (100000)\nTest\n";
Pattern pattern = PatternUtil.getPattern("supportedLinkModes", speed);
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
System.out.println(matcher.group(1));
} else
System.out.println("no match");
}
示例15: parseInfo
import java.util.regex.Pattern; //導入方法依賴的package包/類
private void parseInfo(final Variation variation, final Allele alt, final Long refId, final Genotype genotype) {
if (genotype != null) {
Map<String, Object> genotypeInfo = new HashMap<>();
if (genotype.getAD() != null) {
genotypeInfo.put("AD", genotype.getAD());
}
genotypeInfo.put("GQ", genotype.getGQ());
genotypeInfo.put("DP", genotype.getDP());
if (genotype.getPL() != null) {
genotypeInfo.put("PL", genotype.getPL());
}
genotypeInfo.put("GT", genotype.getGenotypeString());
}
if (variation.getType() == VariationType.BND && variation.getBindInfo() == null) {
variation.setBindInfo(new HashMap<>());
for (Pattern pattern : BIND_PATTERNS) {
Matcher matcher = pattern.matcher(alt.getDisplayString());
if (matcher.matches()) {
String chrName = matcher.group(1);
Optional<Chromosome> chromosome = referenceGenomeManager.loadChromosomes(refId)
.stream()
.filter(c -> c.getName().equals(chrName) ||
c.getName().equals(Utils.changeChromosomeName(chrName)))
.findAny();
variation.getBindInfo().put(BIND_CHR_ATTRIBUTE, chromosome.isPresent() ?
chromosome.get().getId() : chrName);
variation.getBindInfo().put(BIND_POS_ATTRIBUTE, matcher.group(2));
break;
}
}
}
}