當前位置: 首頁>>代碼示例>>Java>>正文


Java Pattern.matcher方法代碼示例

本文整理匯總了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 "";

	}
 
開發者ID:Esri,項目名稱:defense-solutions-proofs-of-concept,代碼行數:22,代碼來源:CoTAdapter.java

示例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();
}
 
開發者ID:honnix,項目名稱:rkt-launcher,代碼行數:18,代碼來源:Rm.java

示例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;
}
 
開發者ID:afiqiqmal,項目名稱:MVP-Android,代碼行數:13,代碼來源:CommonUtils.java

示例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;
}
 
開發者ID:lyy4j,項目名稱:rmq4note,代碼行數:14,代碼來源:Validators.java

示例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) {
            }
        }
    }

}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:34,代碼來源:QMUIImageSizeDetector.java

示例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 "";
    }
}
 
開發者ID:Azure,項目名稱:device-telemetry-java,代碼行數:12,代碼來源:StorageConfig.java

示例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;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:19,代碼來源:BatchBodyParser.java

示例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));
	}
}
 
開發者ID:LAW-Unimi,項目名稱:BUbiNG,代碼行數:40,代碼來源:DuplicateSegmentsLessThan.java

示例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;
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:30,代碼來源:AbstractRepositoryIterator.java

示例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);
    }
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:29,代碼來源:ConnectionRegressionTest.java

示例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);
    }
}
 
開發者ID:dajudge,項目名稱:testee.fi,代碼行數:15,代碼來源:ClasspathTransform.java

示例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;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:38,代碼來源:Canary.java

示例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;
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:11,代碼來源:ConfigElement.java

示例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");
    }
 
開發者ID:fast-data-transfer,項目名稱:fdt,代碼行數:11,代碼來源:InterfaceHandler.java

示例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;
            }
        }
    }
}
 
開發者ID:react-dev26,項目名稱:NGB-master,代碼行數:35,代碼來源:VcfGa4ghReader.java


注:本文中的java.util.regex.Pattern.matcher方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。