本文整理汇总了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;
}
示例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()]);
}
示例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");
}
}
示例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);
}
});
}
}
示例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'");
}
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
示例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;
}
示例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();
}
示例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<>();
}
示例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;
}
示例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;
}
示例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;
}