本文整理了Java中java.util.regex.Matcher.reset()
方法的一些代码示例,展示了Matcher.reset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matcher.reset()
方法的具体详情如下:
包路径:java.util.regex.Matcher
类名称:Matcher
方法名:reset
[英]Resets the Matcher. This results in the region being set to the whole input. Results of a previous find get lost. The next attempt to find an occurrence of the Pattern in the string will start at the beginning of the input.
[中]重置匹配器。这将导致将区域设置为整个输入。以前查找的结果将丢失。下一次在字符串中查找模式匹配项的尝试将从输入的开头开始。
代码示例来源:origin: stackoverflow.com
Pattern p = Pattern.compile("\\d+");
Matcher m = p.matcher("");
for (String s : myStringList) {
if ( m.reset(s).matches() ) {
doSomething();
}
}
代码示例来源:origin: aragozin/jvm-tools
@Override
public boolean accept(String threadName) {
if (threadName != null) {
matcher.reset(threadName);
return matcher.matches();
}
else {
return false;
}
}
};
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* Find the number of Strings matched to the given Matcher.
*
* @param matcher a Matcher
* @return int the number of Strings matched to the given matcher.
* @since 1.0
*/
public static int getCount(Matcher matcher) {
int counter = 0;
matcher.reset();
while (matcher.find()) {
counter++;
}
return counter;
}
代码示例来源:origin: openhab/openhab1-addons
/**
* Extracts username and password from the given <code>url</code>. A valid
* url to extract {@link Credentials} from looks like:
*
* <pre>
* http://username:password@www.domain.org
* </pre>
*
* @param url the URL to extract {@link Credentials} from
*
* @return the exracted Credentials or <code>null</code> if the given
* <code>url</code> does not contain credentials
*/
protected static Credentials extractCredentials(String url) {
Matcher matcher = URL_CREDENTIALS_PATTERN.matcher(url);
if (matcher.matches()) {
matcher.reset();
String username = "";
String password = "";
while (matcher.find()) {
username = matcher.group(1);
password = matcher.group(2);
}
Credentials credentials = new UsernamePasswordCredentials(username, password);
return credentials;
}
return null;
}
代码示例来源:origin: org.apache.lucene/lucene-core
private void checkFileNames(Collection<String> files) {
Matcher m = IndexFileNames.CODEC_FILE_PATTERN.matcher("");
for (String file : files) {
m.reset(file);
if (!m.matches()) {
throw new IllegalArgumentException("invalid codec filename '" + file + "', must match: " + IndexFileNames.CODEC_FILE_PATTERN.pattern());
}
if (file.toLowerCase(Locale.ROOT).endsWith(".tmp")) {
throw new IllegalArgumentException("invalid codec filename '" + file + "', cannot end with .tmp extension");
}
}
}
代码示例来源:origin: spockframework/spock
String nameFor(Object... dataValues) {
StringBuffer result = new StringBuffer();
expressionMatcher.reset();
while (expressionMatcher.find()) {
String expr = expressionMatcher.group(1);
String value = evaluateExpression(expr, dataValues);
expressionMatcher.appendReplacement(result, Matcher.quoteReplacement(value));
}
expressionMatcher.appendTail(result);
iterationCount++;
return result.toString();
}
代码示例来源:origin: apache/hive
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
String substr = text.substring(position);
Matcher matcher = numericMatcher.get();
matcher.reset(substr);
if (!matcher.matches()) {
return -1;
}
// Joda DateTime only has precision to millis, cut off any fractional portion
long millis = Long.parseLong(matcher.group(1));
DateTime dt =
new DateTime(millis, ISOChronology.getInstanceUTC());
for (DateTimeFieldType field : dateTimeFields) {
bucket.saveField(field, dt.get(field));
}
return substr.length();
}
}
代码示例来源:origin: prometheus/jmx_exporter
public LinkedHashMap<String, String> getKeyPropertyList(ObjectName mbeanName) {
LinkedHashMap<String, String> keyProperties = keyPropertiesPerBean.get(mbeanName);
if (keyProperties == null) {
keyProperties = new LinkedHashMap<String, String>();
String properties = mbeanName.getKeyPropertyListString();
Matcher match = PROPERTY_PATTERN.matcher(properties);
while (match.lookingAt()) {
keyProperties.put(match.group(1), match.group(2));
properties = properties.substring(match.end());
if (properties.startsWith(",")) {
properties = properties.substring(1);
}
match.reset(properties);
}
keyPropertiesPerBean.put(mbeanName, keyProperties);
}
return keyProperties;
}
代码示例来源:origin: languagetool-org/languagetool
boolean[] matchedWord = {false, false};
Matcher[] matchers = {null, null};
matchers[0] = contextWords.words[0].matcher("");
matchers[1] = contextWords.words[1].matcher("");
for (i = 1; i < tokens.length && !matchedWord[0]; i++) {
token1 = tokens[i].getToken();
matchedWord[0] = matchers[0].reset(token1).find();
for (j = 1; j < tokens.length && !matchedWord[1]; j++) {
token2 = tokens[j].getToken();
matchedWord[1] = matchers[1].reset(token2).find();
String lemma = tokens[i].getAnalyzedToken(j).getLemma();
if (lemma != null && !lemma.isEmpty()) {
matchedContext[foundWord] = matchers[foundWord].reset(lemma).find();
matchedContext[foundWord] = matchers[foundWord].reset(token).find();
String lemma = tokens[i].getAnalyzedToken(j).getLemma();
if (lemma != null && !lemma.isEmpty()) {
matchedContext[notFoundWord] = matchers[notFoundWord].reset(lemma).find();
matchedContext[notFoundWord] = matchers[notFoundWord].reset(token).find();
代码示例来源:origin: stanfordnlp/CoreNLP
private static Iterator<String> splitIntoDocs(Reader r) {
if (TREAT_FILE_AS_ONE_DOCUMENT) {
return Collections.singleton(IOUtils.slurpReader(r)).iterator();
} else {
Collection<String> docs = new ArrayList<>();
ObjectBank<String> ob = ObjectBank.getLineIterator(r);
StringBuilder current = new StringBuilder();
Matcher matcher = docPattern.matcher("");
for (String line : ob) {
if (matcher.reset(line).lookingAt()) {
// Start new doc, store old one if non-empty
if (current.length() > 0) {
docs.add(current.toString());
current.setLength(0);
}
}
current.append(line).append('\n');
}
if (current.length() > 0) {
docs.add(current.toString());
}
return docs.iterator();
}
}
代码示例来源:origin: oracle/opengrok
@Override
public void processStream(InputStream input) throws IOException {
try (BufferedReader in = new BufferedReader(new InputStreamReader(input))) {
String line = "";
int lineno = 0;
Matcher matcher = BLAME_PATTERN.matcher(line);
while ((line = in.readLine()) != null) {
++lineno;
matcher.reset(line);
if (matcher.find()) {
String rev = matcher.group(1);
String author = matcher.group(2).trim();
annotation.addLine(rev, author, true);
} else {
LOGGER.log(Level.SEVERE,
"Error: did not find annotation in line {0}: [{1}]",
new Object[]{String.valueOf(lineno), line});
}
}
}
}
}
代码示例来源:origin: square/wire
/**
* Returns true if any of the options in {@code options} matches both of the regular expressions
* provided: its name matches the option's name and its value matches the option's value.
*/
public boolean optionMatches(String namePattern, String valuePattern) {
Matcher nameMatcher = Pattern.compile(namePattern).matcher("");
Matcher valueMatcher = Pattern.compile(valuePattern).matcher("");
for (Map.Entry<ProtoMember, Object> entry : map.entrySet()) {
if (nameMatcher.reset(entry.getKey().member()).matches()
&& valueMatcher.reset(String.valueOf(entry.getValue())).matches()) {
return true;
}
}
return false;
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public Iterable<String> convertRecord(Class<String> outputSchema, String inputRecord, WorkUnitState workUnit)
throws DataConversionException {
if (!this.matcher.isPresent()) {
this.matcher = Optional.of(this.pattern.matcher(inputRecord));
} else {
this.matcher.get().reset(inputRecord);
}
return this.matcher.get().matches() ? new SingleRecordIterable<>(inputRecord) : new EmptyIterable<String>();
}
}
代码示例来源:origin: alibaba/mdrill
yyyymmdd_matcher.reset(string);
int len=string.length();
if(len==8&&yyyymmdd_matcher.find()){
return yyyymmdd_matcher.group(1)+"-"+yyyymmdd_matcher.group(2)+"-"+yyyymmdd_matcher.group(3)+"T00:00:00Z";
yyyy_mm_dd_matcher.reset(string);
if(len==10&&yyyy_mm_dd_matcher.find()){
return yyyy_mm_dd_matcher.group(1)+"-"+yyyy_mm_dd_matcher.group(2)+"-"+yyyy_mm_dd_matcher.group(3)+"T00:00:00Z";
yyyy_mm_dd_2_matcher.reset(string);
if(len==10&&yyyy_mm_dd_2_matcher.find()){
return yyyy_mm_dd_2_matcher.group(1)+"-"+yyyy_mm_dd_2_matcher.group(2)+"-"+yyyy_mm_dd_2_matcher.group(3)+"T00:00:00Z";
yyyymmddhhsshh_matcher.reset(string);
if(len==14&&yyyymmddhhsshh_matcher.find()){
yyyy_mm_dd_hh_ss_hh_matcher.reset(string);
if(len==19&&yyyy_mm_dd_hh_ss_hh_matcher.find()){
valid_matcher.reset(string);
if(valid_matcher.find()){
代码示例来源:origin: apache/hive
patternMatcher.reset(strVal);
if (patternMatcher.matches()) {
String field = patternMatcher.group(1);
if (field != null && field.equals("-")) {
sign = -1;
DateUtils.parseNumericValueWithRange("year", patternMatcher.group(2),
0, Integer.MAX_VALUE);
byte months = (byte) (sign *
DateUtils.parseNumericValueWithRange("month", patternMatcher.group(3), 0, 11));
result = new HiveIntervalYearMonth(years, months);
} catch (Exception err) {
代码示例来源:origin: apache/tika
/**
* Add a key-value pair to pass to Tesseract using its -c command line option.
* To see the possible options, run tesseract --print-parameters.
*
* You may also add these parameters in TesseractOCRConfig.properties; any
* key-value pair in the properties file where the key contains an underscore
* is passed directly to Tesseract.
*
* @param key
* @param value
*/
public void addOtherTesseractConfig(String key, String value) {
if (key == null) {
throw new IllegalArgumentException("key must not be null");
}
if (value == null) {
throw new IllegalArgumentException("value must not be null");
}
Matcher m = ALLOWABLE_OTHER_PARAMS_PATTERN.matcher(key);
if (! m.find()) {
throw new IllegalArgumentException("Key contains illegal characters: "+key);
}
m.reset(value);
if (! m.find()) {
throw new IllegalArgumentException("Value contains illegal characters: "+value);
}
otherTesseractConfig.put(key.trim(), value.trim());
}
代码示例来源:origin: chewiebug/GCViewer
private boolean isMixedLine(String line, Matcher mixedLineMatcher) {
mixedLineMatcher.reset(line);
return mixedLineMatcher.matches();
}
代码示例来源:origin: apache/hive
public boolean check(byte[] byteS, int start, int len) {
// Match the given bytes with the like pattern
matcher.reset(decoder.decodeUnsafely(byteS, start, len));
return matcher.find(0);
}
}
代码示例来源:origin: robovm/robovm
private void resetMatcher() {
if (matcher == null) {
matcher = delimiter.matcher(buffer);
} else {
matcher.reset(buffer);
}
matcher.useTransparentBounds(true);
matcher.useAnchoringBounds(false);
matcher.region(findStartIndex, bufferLength);
}
代码示例来源:origin: apache/flink
public static void checkLinesAgainstRegexp(String resultPath, String regexp){
Pattern pattern = Pattern.compile(regexp);
Matcher matcher = pattern.matcher("");
ArrayList<String> list = new ArrayList<>();
try {
readAllResultLines(list, resultPath, new String[]{}, false);
} catch (IOException e1) {
Assert.fail("Error reading the result");
}
for (String line : list){
matcher.reset(line);
if (!matcher.find()){
String msg = "Line is not well-formed: " + line;
Assert.fail(msg);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!