当前位置: 首页>>代码示例>>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;未经允许,请勿转载。