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


Java Matcher類代碼示例

本文整理匯總了Java中java.util.regex.Matcher的典型用法代碼示例。如果您正苦於以下問題:Java Matcher類的具體用法?Java Matcher怎麽用?Java Matcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Matcher類屬於java.util.regex包,在下文中一共展示了Matcher類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: marathon_select

import java.util.regex.Matcher; //導入依賴的package包/類
@Override public boolean marathon_select(String tab) {
    Matcher matcher = CLOSE_PATTERN.matcher(tab);
    boolean isCloseTab = matcher.matches();
    tab = isCloseTab ? matcher.group(1) : tab;
    TabPane tp = (TabPane) node;
    ObservableList<Tab> tabs = tp.getTabs();
    for (int index = 0; index < tabs.size(); index++) {
        String current = getTextForTab(tp, tabs.get(index));
        if (tab.equals(current)) {
            if (isCloseTab) {
                ((TabPaneSkin) tp.getSkin()).getBehavior().closeTab(tabs.get(index));
                return true;
            }
            tp.getSelectionModel().select(index);
            return true;
        }
    }
    return false;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:20,代碼來源:JavaFXTabPaneElement.java

示例2: splitWithQuotes

import java.util.regex.Matcher; //導入依賴的package包/類
/**
 * Split a message from whitespaces, ignoring the one in quotes.<br><br>
 *
 * <b>Example :</b>
 *
 * <pre>
 *     I am a "discord bot"
 * </pre>
 *
 * Will return ["I", "am", "a", "discord bot"].
 *
 * @param line The line to split
 *
 * @return The line split
 */
public static String[] splitWithQuotes(String line)
{
    ArrayList<String> matchList = new ArrayList<>();
    Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'");
    Matcher matcher = regex.matcher(line);

    while (matcher.find())
    {
        if (matcher.group(1) != null)
        {
            matchList.add(matcher.group(1));
        }
        else if (matcher.group(2) != null)
        {
            matchList.add(matcher.group(2));
        }
        else
        {
            matchList.add(matcher.group());
        }
    }

    return matchList.toArray(new String[matchList.size()]);
}
 
開發者ID:krobot-framework,項目名稱:krobot,代碼行數:40,代碼來源:CommandManager.java

示例3: match

import java.util.regex.Matcher; //導入依賴的package包/類
public static void match() {
	// 按指定模式在字符串查找
	String line = "This order was placed for QT3000! OK?";
	String pattern = "(\\D*)(\\d+)(.*)";

	// 創建 Pattern 對象
	Pattern r = Pattern.compile(pattern);

	// 現在創建 matcher 對象
	Matcher m = r.matcher(line);
	if (m.groupCount() > 0) {
		System.out.println(m.groupCount());
		for (int i = 0; i < m.groupCount(); i++) {
			System.out.println("Found value: " + m.group(i));
		}
	} else {
		System.out.println("NO MATCH");
	}
}
 
開發者ID:leon66666,項目名稱:JavaCommon,代碼行數:20,代碼來源:RegexDemo.java

示例4: call

import java.util.regex.Matcher; //導入依賴的package包/類
@Override
public void call(T ignored) throws IOException {
  Path dataDirPath = new Path(dataDirString + "/*");
  FileSystem fs = FileSystem.get(dataDirPath.toUri(), hadoopConf);
  FileStatus[] inputPathStatuses = fs.globStatus(dataDirPath);
  if (inputPathStatuses != null) {
    long oldestTimeAllowed =
        System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(maxAgeHours, TimeUnit.HOURS);
    Arrays.stream(inputPathStatuses).filter(FileStatus::isDirectory).map(FileStatus::getPath).
        filter(subdir -> {
          Matcher m = dirTimestampPattern.matcher(subdir.getName());
          return m.find() && Long.parseLong(m.group(1)) < oldestTimeAllowed;
        }).forEach(subdir -> {
          log.info("Deleting old data at {}", subdir);
          try {
            fs.delete(subdir, true);
          } catch (IOException e) {
            log.warn("Unable to delete {}; continuing", subdir, e);
          }
        });
  }
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:23,代碼來源:DeleteOldDataFn.java

示例5: createExpression

import java.util.regex.Matcher; //導入依賴的package包/類
@VisibleForTesting
protected Expression createExpression(String value) {
  if (value.matches("\\d*(\\.\\d*)?")) {
    return new DoubleValue(Double.valueOf(value));
  } else if (value.matches("[a-zA-Z]+")) {
    return new Variable(value);
  }
  Matcher binaryMatcher = binaryOperationPattern.matcher(value);
  Matcher unaryMatcher = unaryOperationPattern.matcher(value);

  if (binaryMatcher.matches()) {
    return createBinaryExpression(binaryMatcher);
  } else if (unaryMatcher.matches()) {
    return createUnaryExpression(unaryMatcher);
  } else {
    throw new IllegalArgumentException("Invalid expression " + value + " Try something like: 'a+b' or '2'");
  }
}
 
開發者ID:apache,項目名稱:incubator-ratis,代碼行數:19,代碼來源:Assign.java

示例6: getDictionaryVersion

import java.util.regex.Matcher; //導入依賴的package包/類
/**
 * @param fs Filesystem
 * @param tableDir root of parquet table
 * @return the highest dictionary version found, -1 if no dictionaries are present
 * @throws IOException
 */
public static long getDictionaryVersion(FileSystem fs, Path tableDir) throws IOException {
  final FileStatus[] statuses = fs.listStatus(tableDir, DICTIONARY_ROOT_FILTER);
  long maxVersion = -1;
  for (FileStatus status : statuses) {
    if (status.isDirectory()) {
      Matcher matcher = DICTIONARY_VERSION_PATTERN.matcher(status.getPath().getName());
      if (matcher.find()) {
        try {
          final long version = Long.parseLong(matcher.group(1));
          if (version > maxVersion) {
            maxVersion = version;
          }
        } catch (NumberFormatException nfe) {
        }
      }
    }
  }
  return maxVersion;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:26,代碼來源:GlobalDictionaryBuilder.java

示例7: getPHs

import java.util.regex.Matcher; //導入依賴的package包/類
public HashMap<String, List<SPH>> getPHs(String message){
	Matcher m = pattern.matcher(message);
	HashMap<String, List<SPH>>result = new HashMap<String, List<SPH>>();
	while (m.find()) {
		String key = m.group(1);
		List<SPH>s = result.get(key);
		if(s==null){
			s=new ArrayList<SPH>();
			result.put(key, s);
		}
		String suffix = null;
		if(m.groupCount() > 1){
			suffix = m.group(2);
		}
		s.add(getInstance(suffix));
	}
	return result;
}
 
開發者ID:dracnis,項目名稱:VanillaPlus,代碼行數:19,代碼來源:SPHSuffix.java

示例8: handleToolLeader

import java.util.regex.Matcher; //導入依賴的package包/類
private WebResponse handleToolLeader(WebResponse resp) throws SAXException, IOException {
String asText = resp.getText();
Matcher m = MockLearner.LEADER_SHOW_DIALOG_PATTERN.matcher(asText);
if (!m.find()) {
    throw new TestHarnessException("Could not tell whether the user can become the leader");
}
if (Boolean.valueOf(m.group(1))) {
    m = MockLearner.LEADER_BECOME_PATTERN.matcher(asText);
    if (!m.find()) {
	throw new TestHarnessException("Could not \"become leader\" URL");
    }
    String becomeLeaderQueryOptions = m.group();
    String url = "/lams/tool/lalead11/learning.do?" + becomeLeaderQueryOptions;
    MockLearner.log.debug("Becoming a leader using link: " + url);
    new Call(wc, test, username + " becomes Leader", url).execute();
}
String finishURL = MockLearner.findURLInLocationHref(resp, MockLearner.LEADER_FINISH_SUBSTRING);
if (finishURL == null) {
    throw new TestHarnessException("Unable to finish the leader, no finish link found. " + asText);
}

MockLearner.log.debug("Ending leader using url " + finishURL);
return (WebResponse) new Call(wc, test, username + " finishes Leader", finishURL).execute();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:MockLearner.java

示例9: downloadURL

import java.util.regex.Matcher; //導入依賴的package包/類
/**
 * 判斷需要下載的資源
 * 
 * @param url
 *            {@link URL}
 * @param html
 *            {@link String}
 */
public void downloadURL(String url, String html) {
	Matcher matcher;
	if (CrawlConfig.getCrawlImages().get()) {
		matcher = IMAGES_PATTERN.matcher(html);
		addURLs("image", matcher);
	}
	if (CrawlConfig.getCrawlVideos().get()) {
		matcher = VIDEOS_PATTERN.matcher(html);
		addURLs("media", matcher);
	}
	if (CrawlConfig.getCrawlDocs().get()) {
		matcher = DOCS_PATTERN.matcher(html);
		addURLs("document", matcher);
	}
	if (CrawlConfig.getCrawlOthers().get()) {
		matcher = OTHERS_PATTERN.matcher(html);
		addURLs("others", matcher);
	}
	if (Checker.isNotEmpty(url) && CrawlConfig.getCrawlLinks().get()) {
		String path = App.DOWNLOAD_FOLDER + Values.SEPARATOR + "link";
		Downloader.download(path, (url.startsWith("//") ? "http:" : "") + url);
	}
}
 
開發者ID:zhazhapan,項目名稱:visual-spider,代碼行數:32,代碼來源:Crawler.java

示例10: regex_offset

import java.util.regex.Matcher; //導入依賴的package包/類
private List<Integer> regex_offset(String line) {

        List<Integer> found_offsets = new ArrayList<>();

        // Cusips are 9 characters and can contain numbers and letters
        String pattern = "[A-Za-z0-9]{9}";
        Pattern finder = Pattern.compile(pattern);
        Matcher matcher = finder.matcher(line);

        // Every candidate gets added to the list
        while (matcher.find()) {
            found_offsets.add(matcher.start());
        }

        return found_offsets;
    }
 
開發者ID:bws0013,項目名稱:read_13f,代碼行數:17,代碼來源:File_Processor_Old.java

示例11: resolveEmbeddedEnvVariables

import java.util.regex.Matcher; //導入依賴的package包/類
private String resolveEmbeddedEnvVariables(final String projectKey, final EnvVars env, final Pattern pattern, final int braceOffset) {

        final Matcher matcher = pattern.matcher(projectKey);
        final StringBuilder builder = new StringBuilder(projectKey);
        boolean matchesFound = false;
        int offset = 0;

        while (matcher.find()) {
            final String envVariable = projectKey.substring(matcher.start() + braceOffset + 1, matcher.end() - braceOffset);
            final String envValue = env.get(envVariable);

            if (envValue == null) {
                throw new QGException("Environment Variable [" + envVariable + "] not found");
            }

            builder.replace(matcher.start() + offset, matcher.end() + offset, envValue);
            offset += envValue.length() - matcher.group(1).length();
            matchesFound = true;
        }

        if (matchesFound) {
            return getProjectKey(builder.toString(), env);
        }

        return builder.toString();
    }
 
開發者ID:jenkinsci,項目名稱:sonar-quality-gates-plugin,代碼行數:27,代碼來源:JobConfigurationService.java

示例12: getAttributesInternal

import java.util.regex.Matcher; //導入依賴的package包/類
@Override
protected Map<String, Object> getAttributesInternal(final Principal principal,
                                                    final Map<String, Object> attributes,
                                                    final RegisteredService service) {
    try {
        if (StringUtils.isBlank(this.scriptFile)) {
            return new HashMap<>();
        }
        final Matcher matcherInline = INLINE_GROOVY_PATTERN.matcher(this.scriptFile);
        if (matcherInline.find()) {
            return getAttributesFromInlineGroovyScript(attributes, matcherInline);
        }
        return getScriptedAttributesFromFile(attributes);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return new HashMap<>();
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:19,代碼來源:ScriptedRegisteredServiceAttributeReleasePolicy.java

示例13: parse

import java.util.regex.Matcher; //導入依賴的package包/類
public ExpressionParser parse() {
	Matcher matcher = this.pattern.matcher(this.query);
	List<String> matches = new ArrayList<>();
	while (matcher.find()) matches.add(matcher.group());
	terms = new ArrayList<>();
	operations = new ArrayList<>();
	String global = "";
	for (String string : matches) {
		if (string.equals(PLUS) || string.equals(MINUS)) {
			operations.add(string);
		} else {
			global = global.concat(string);
			terms.add(cleanString(string));
		}
	}
	Matcher matcher2 = this.pattern2.matcher(this.query);
	while (matcher2.find()) operations.add(matcher2.group());
	terms.add(this.query.replace(global, "").trim());
	return this;
}
 
開發者ID:IsaacChanghau,項目名稱:Word2VecfJava,代碼行數:21,代碼來源:ExpressionParser.java

示例14: checkHashRestfulPlaceholder

import java.util.regex.Matcher; //導入依賴的package包/類
/**
 * @param url
 * @param paramsMap
 * @return
 * @Description 檢測url中是否有restful風格的占位符,比如/{sessionId}/token中的sessionId,從paramsMap中替換
 */
private static String checkHashRestfulPlaceholder(String url, Map<String, Object> paramsMap) {
    Pattern pattern = Pattern.compile("(\\{\\w+\\})");
    Matcher matcher = pattern.matcher(url);

    String resultUrl = url;

    String plaseholder = "";
    String mapKey = "";
    while (matcher.find()) {
        plaseholder = matcher.group(1);
        mapKey = plaseholder.substring(1, plaseholder.length() - 1);
        //如果有占位符Map中未get到,直接跳出這組指標規則循環繼續下一組
        resultUrl = url.replace(plaseholder, String.valueOf(paramsMap.get(mapKey)));
    }
    return resultUrl;
}
 
開發者ID:fanqinghui,項目名稱:wish-pay,代碼行數:23,代碼來源:HttpClientUtils.java

示例15: tokenize

import java.util.regex.Matcher; //導入依賴的package包/類
public List<Tokenization> tokenize(List<String> sentences) {
	List<Tokenization> tokenizations = new ArrayList<>();
	int accumulatedSentenceLength = 0;
	for (String sentence : sentences) {
		int index = 0;
		Matcher matcher = pattern.matcher(sentence);
		List<Token> tokens = new ArrayList<>();
		while (matcher.find()) {
			String text = matcher.group();
			int from = matcher.start();
			int to = matcher.end();
			tokens.add(new Token(index, from, to, text));
			index++;
		}
		Tokenization tokenization = new Tokenization(tokens, sentence, accumulatedSentenceLength);
		tokenizations.add(tokenization);
		accumulatedSentenceLength += sentence.length();
		// System.out.println(tokenization.originalSentence);
		// System.out.println(
		// tokenization.tokens.stream().reduce("", (s, t) -> s + " " +
		// t.getText(), (s, tt) -> s + tt));
	}
	return tokenizations;
}
 
開發者ID:ag-sc,項目名稱:JLink,代碼行數:25,代碼來源:SimpleRegexTokenizer.java


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