java.util.regex.Matcher.lookingAt()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中java.util.regex.Matcher.lookingAt()方法的一些代码示例,展示了Matcher.lookingAt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matcher.lookingAt()方法的具体详情如下:
包路径:java.util.regex.Matcher
类名称:Matcher
方法名:lookingAt

Matcher.lookingAt介绍

[英]Tries to match the Pattern, starting from the beginning of the region (or the beginning of the input, if no region has been set). Doesn't require the Pattern to match against the whole region.
[中]尝试匹配模式,从区域的开始(或输入的开始,如果未设置区域)。不需要模式匹配整个区域。

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Say whether this regular expression can be found at the beginning of
 * this String.  This method provides one of the two "missing"
 * convenience methods for regular expressions in the String class
 * in JDK1.4.
 *
 * @param str   String to search for match at start of
 * @param regex String to compile as the regular expression
 * @return Whether the regex can be found at the start of str
 */
public static boolean lookingAt(String str, String regex) {
 return Pattern.compile(regex).matcher(str).lookingAt();
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Override
boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) {
  final Matcher matcher = pattern.matcher(source.substring(pos.getIndex()));
  if (!matcher.lookingAt()) {
    pos.setErrorIndex(pos.getIndex());
    return false;
  }
  pos.setIndex(pos.getIndex() + matcher.end(1));
  setCalendar(parser, calendar, matcher.group(1));
  return true;
}

代码示例来源:origin: stanfordnlp/CoreNLP

mig = ignoreRegexp.matcher(word);
if (mig != null && mig.lookingAt()) {
 word = word.substring(mig.end());
} else {
 Matcher m = tokenizerRegexp.matcher(word);
 if (m.lookingAt()) {
  al.add(word.substring(0, m.end()));
  word = word.substring(m.end());
 } else {
  logger.info("Warning: regexpTokenize pattern " + tokenizerRegexp + " didn't match on |" +

代码示例来源:origin: google/error-prone

/**
 * Extracts the long literal corresponding to a given {@link LiteralTree} node from the source
 * code as a string. Returns null if the source code is not available.
 */
private static String getLongLiteral(LiteralTree literalTree, VisitorState state) {
 JCLiteral longLiteral = (JCLiteral) literalTree;
 CharSequence sourceFile = state.getSourceCode();
 if (sourceFile == null) {
  return null;
 }
 int start = longLiteral.getStartPosition();
 java.util.regex.Matcher matcher =
   LONG_LITERAL_PATTERN.matcher(sourceFile.subSequence(start, sourceFile.length()));
 if (matcher.lookingAt()) {
  return matcher.group();
 }
 return null;
}

代码示例来源:origin: stackoverflow.com

Pattern pattern = Pattern.compile("([0-9_]+v._.)");
Matcher matcher = pattern.matcher("117_117_0009v0_172_5738_5740");
if (matcher.lookingAt()) {
 int groupCount = matcher.groupCount();
 for (int i = 0; i <= groupCount; i++) {
   System.out.println(i + " : " + matcher.group(i));
 }
}

代码示例来源:origin: osmandapp/Osmand

} else {
 matcher.usePattern(TOKEN);
 if (matcher.lookingAt()) {
  currentToken = matcher.group();
  matcher.region(matcher.end(), matcher.regionEnd());
 } else {

代码示例来源:origin: osmandapp/Osmand

/**
 * Skip over any whitespace so that the matcher region starts at the next
 * token.
 */
private void skipWhitespace() {
 matcher.usePattern(WHITESPACE);
 if (matcher.lookingAt()) {
  matcher.region(matcher.end(), matcher.regionEnd());
 }
}

代码示例来源:origin: square/okhttp

Matcher typeSubtype = TYPE_SUBTYPE.matcher(string);
if (!typeSubtype.lookingAt()) {
 throw new IllegalArgumentException("No subtype found for: \"" + string + '"');
String type = typeSubtype.group(1).toLowerCase(Locale.US);
String subtype = typeSubtype.group(2).toLowerCase(Locale.US);
Matcher parameter = PARAMETER.matcher(string);
for (int s = typeSubtype.end(); s < string.length(); s = parameter.end()) {
 parameter.region(s, string.length());
 if (!parameter.lookingAt()) {
  throw new IllegalArgumentException("Parameter is not formatted correctly: \""
    + string.substring(s)
 String name = parameter.group(1);
 if (name == null || !name.equalsIgnoreCase("charset")) continue;
 String charsetParameter;

代码示例来源:origin: square/javapoet

checkArgument(LOWERCASE.matcher(argument).matches(),
  "argument '%s' must start with a lowercase character", argument);
if (colon != -1) {
 int endIndex = Math.min(colon + 2, format.length());
 matcher = NAMED_ARGUMENT.matcher(format.substring(p, endIndex));
if (matcher != null && matcher.lookingAt()) {
 String argumentName = matcher.group("argumentName");
 checkArgument(arguments.containsKey(argumentName), "Missing named argument for $%s",
   argumentName);
 char formatChar = matcher.group("typeChar").charAt(0);
 addArgument(format, formatChar, arguments.get(argumentName));
 formatParts.add("$" + formatChar);

代码示例来源:origin: bytedeco/javacpp

boolean tagFound = false;
for (DocTag tag : DocTag.docTags) {
  Matcher matcher = tag.pattern.matcher(ss);
  if (matcher.lookingAt()) {
    StringBuffer sbuf = new StringBuffer();
    matcher.appendReplacement(sbuf, tag.replacement);
        !Character.isWhitespace(sb.charAt(index + matcher.end() + 1))) {
      sbuf.append(' ');
          index + 1 + matcher.end(), sbuf.toString());
    index += sbuf.length() - 1;
    tagFound = true;

代码示例来源:origin: aragozin/jvm-tools

@Override
  public boolean evaluate(StackFrame frame) {
    return regEx.matcher(frame).lookingAt();
  }
}

代码示例来源:origin: com.google.protobuf/protobuf-java

} else {
 matcher.usePattern(TOKEN);
 if (matcher.lookingAt()) {
  currentToken = matcher.group();
  matcher.region(matcher.end(), matcher.regionEnd());
 } else {

代码示例来源:origin: com.google.protobuf/protobuf-java

/**
 * Skip over any whitespace so that the matcher region starts at the next
 * token.
 */
private void skipWhitespace() {
 matcher.usePattern(WHITESPACE);
 if (matcher.lookingAt()) {
  matcher.region(matcher.end(), matcher.regionEnd());
 }
}

代码示例来源:origin: looly/hutool

@Override
boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) {
  final Matcher matcher = pattern.matcher(source.substring(pos.getIndex()));
  if (!matcher.lookingAt()) {
    pos.setErrorIndex(pos.getIndex());
    return false;
  }
  pos.setIndex(pos.getIndex() + matcher.end(1));
  setCalendar(parser, calendar, matcher.group(1));
  return true;
}

代码示例来源:origin: EngineHub/WorldEdit

final Matcher numberMatcher = numberPattern.matcher(expression.substring(position));
if (numberMatcher.lookingAt()) {
  String numberPart = numberMatcher.group(1);
  if (!numberPart.isEmpty()) {
    try {
final Matcher identifierMatcher = identifierPattern.matcher(expression.substring(position));
if (identifierMatcher.lookingAt()) {
  String identifierPart = identifierMatcher.group(1);
  if (!identifierPart.isEmpty()) {
    if (keywords.contains(identifierPart)) {

代码示例来源:origin: apache/httpcomponents-client

protected void consumeWarnDate() {
  final int curr = offs;
  final Matcher m = WARN_DATE_PATTERN.matcher(src.substring(offs));
  if (!m.lookingAt()) {
    parseError();
  }
  offs += m.end();
  warnDate = DateUtils.parseDate(src.substring(curr+1,offs-1));
}

代码示例来源:origin: stanfordnlp/CoreNLP

public boolean setOptions(Properties opts) {
 for(String opt : opts.stringPropertyNames()) {
  String value = opts.getProperty(opt);
  if(value == null) {
   System.err.printf("%s: Read parameter with null value (%s)\n", this.getClass().getName(),opt);
   continue;
  }
  configuredOptions.add(opt);
  Matcher pathMatcher = ConfigParser.matchPath.matcher(opt);
  if(pathMatcher.lookingAt()) {
   pathsToData.add(new File(value));
   configuredOptions.add(ConfigParser.paramPath);
  } else if(opt.equals(ConfigParser.paramName)) {
   Matcher inThisFilename = fileNameNormalizer.matcher(value.trim());
   outFileName = inThisFilename.replaceAll("-");
   toStringBuffer.append(String.format("Dataset Name: %s\n",value.trim()));
  }
 }
 if(!configuredOptions.containsAll(requiredOptions))
  return false;
 //Finalize the output file names
 outFileName += ".txt";
 //Used for codifying lexical hacks
 lexMapper = new DefaultLexicalMapper();
 return true;
}

代码示例来源:origin: aragozin/jvm-tools

protected void parseText() {
  while(true) {
    if (matcher.lookingAt()) {
      offset = matcher.start();
      if (matcher.group(2) != null) {
        processPar();
      else if (matcher.group(3) != null) {
        processPattern();
      else if (matcher.group(4) != null) {
        processOp(TokenType.COMMA, 3);
    if (matcher.end() == text.length()) {
      break;
      matcher.region(matcher.end(), text.length());

代码示例来源:origin: robovm/robovm

matcher.region(findStartIndex, bufferLength);
while (true) {
  if (matcher.lookingAt()) {
    boolean matchInBuffer = matcher.end() < bufferLength
        || (matcher.end() == bufferLength && inputExhausted);
    if (matchInBuffer) {
      matchSuccessful = true;
      findStartIndex = matcher.end();
      break;

代码示例来源:origin: apache/kafka

private static List<KerberosRule> parseRules(String defaultRealm, List<String> rules) {
  List<KerberosRule> result = new ArrayList<>();
  for (String rule : rules) {
    Matcher matcher = RULE_PARSER.matcher(rule);
    if (!matcher.lookingAt()) {
      throw new IllegalArgumentException("Invalid rule: " + rule);
    }
    if (rule.length() != matcher.end())
      throw new IllegalArgumentException("Invalid rule: `" + rule + "`, unmatched substring: `" + rule.substring(matcher.end()) + "`");
    if (matcher.group(2) != null) {
      result.add(new KerberosRule(defaultRealm));
    } else {
      result.add(new KerberosRule(defaultRealm,
          Integer.parseInt(matcher.group(5)),
          matcher.group(6),
          matcher.group(8),
          matcher.group(10),
          matcher.group(11),
          "g".equals(matcher.group(12)),
          "L".equals(matcher.group(13))));
    }
  }
  return result;
}

相关文章