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

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

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

Matcher.pattern介绍

[英]Holds the pattern, that is, the compiled regular expression.
[中]保存模式,即编译后的正则表达式。

代码示例

代码示例来源:origin: hsz/idea-gitignore

/**
 * Extracts alphanumeric parts from {@link Matcher} pattern.
 *
 * @param matcher to handle
 * @return extracted parts
 */
@NotNull
public static String[] getParts(@Nullable Matcher matcher) {
  if (matcher == null) {
    return new String[0];
  }
  return getParts(matcher.pattern());
}

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

/**
 * Returns a string representing this {@code Matcher}.
 * The format of this string is unspecified.
 */
@Override public String toString() {
  return getClass().getName() + "[pattern=" + pattern() +
    " region=" + regionStart() + "," + regionEnd() +
    " lastmatch=" + (matchFound ? group() : "") + "]";
}

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

@Override
public boolean matches(String fileName) {
  // Special case: if no classes or packages have been defined,
  // then the screener matches all class files.
  if (patternList.isEmpty()) {
    return true;
  }
  if (DEBUG) {
    System.out.println("Matching: " + fileName);
  }
  // Scan through list of regexes
  for (Matcher matcher : patternList) {
    if (DEBUG) {
      System.out.print("\tTrying [" + matcher.pattern());
    }
    matcher.reset(fileName);
    if (matcher.find()) {
      if (DEBUG) {
        System.out.println("]: yes!");
      }
      return true;
    }
    if (DEBUG) {
      System.out.println("]: no");
    }
  }
  return false;
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory getPattern(Environment env, Memory... args) {
  return StringMemory.valueOf(matcher.pattern().pattern());
}

代码示例来源:origin: jphp-group/jphp

@Signature(@Arg(value = "flags"))
public Memory withFlags(Environment env, Memory... args) {
  int flags = convertFlags(args[0]);
  Pattern pattern = Pattern.compile(matcher.pattern().pattern(), flags);
  Matcher matcher1 = pattern.matcher(input);
  return ObjectMemory.valueOf(new WrapRegex(env, matcher1, input));
}

代码示例来源:origin: jphp-group/jphp

@FastMethod
@Signature(@Arg("string"))
public Memory test(Environment env, Memory... args) {
  Matcher matcher1 = matcher.pattern().matcher(args[0].toString());
  return TrueMemory.valueOf(matcher1.matches());
}

代码示例来源:origin: jphp-group/jphp

@Signature(@Arg(value = "pattern", nativeType = WrapRegex.class, optional = @Optional("null")))
public Memory hasNext(Environment env, Memory... args) {
  if (args[0].isNull())
    return scanner.hasNext() ? Memory.TRUE : Memory.FALSE;
  else
    return scanner.hasNext(args[0].toObject(WrapRegex.class).getMatcher().pattern()) ? Memory.TRUE : Memory.FALSE;
}

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

if ( matcher.pattern() != PATTERN_FOLLOWING_PROPERTY )

代码示例来源:origin: jphp-group/jphp

@Override
public Pattern convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
  if (arg.instanceOf(WrapRegex.class)) {
    return arg.toObject(WrapRegex.class).getMatcher().pattern();
  } else {
    return Pattern.compile(arg.toString());
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature(@Arg(value = "pattern", nativeType = WrapRegex.class))
public Memory useDelimiter(Environment env, Memory... args) {
  scanner.useDelimiter(args[0].toObject(WrapRegex.class).getMatcher().pattern());
  return new ObjectMemory(this);
}

代码示例来源:origin: ysc/QuestionAnsweringSystem

private List<PatternMatchResultItem> getPatternMatchResultItems(List<String> questionPatterns, QuestionTypePattern questionTypePattern) {
  if (questionPatterns == null || questionPatterns.isEmpty()) {
    LOG.error("模式匹配之前至少指定一个【问题模式】");
    return null;
  }
  if (questionTypePattern == null || questionTypePattern.getPatterns().isEmpty()) {
    LOG.error("模式匹配之前至少指定一个【问题类型模式】");
    return null;
  }
  List<PatternMatchResultItem> patternMatchResultItems = new ArrayList<PatternMatchResultItem>();
  //处理所有的模式
  List<Pattern> patterns = questionTypePattern.getPatterns();
  List<String> types = questionTypePattern.getTypes();
  int len = patterns.size();
  for (int i = 0; i < len; i++) {
    Pattern pattern = patterns.get(i);
    for (String questionPattern : questionPatterns) {
      Matcher m = pattern.matcher(questionPattern);
      if (m.matches()) {
        LOG.info("匹配成功: " + questionPattern + " : " + m.pattern() + " : " + types.get(i));
        PatternMatchResultItem item = new PatternMatchResultItem();
        item.setOrigin(questionPattern);
        item.setPattern(pattern.pattern());
        item.setType(types.get(i));
        patternMatchResultItems.add(item);
      }
    }
  }
  return patternMatchResultItems;
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory getFlags(Environment env, Memory... args) {
  return LongMemory.valueOf(matcher.pattern().flags());
}

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

/** Method that finds the matches. */
private void findMatch() {
  try {
    boolean foundMatch = matcher.find();
    while (foundMatch) {
      currentMatches++;
      if (currentMatches > options.getMaximum()) {
        final LineColumn start = text.lineColumn(matcher.start());
        if (options.getMessage().isEmpty()) {
          options.getReporter().log(start.getLine(),
              MSG_REGEXP_EXCEEDED, matcher.pattern().toString());
        }
        else {
          options.getReporter()
              .log(start.getLine(), options.getMessage());
        }
      }
      foundMatch = matcher.find();
    }
  }
  // see http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6337993 et al.
  catch (StackOverflowError ignored) {
    // OK http://blog.igorminar.com/2008/05/catching-stackoverflowerror-and-bug-in.html
    // http://programmers.stackexchange.com/questions/
    //        209099/is-it-ever-okay-to-catch-stackoverflowerror-in-java
    options.getReporter().log(1, MSG_STACKOVERFLOW, matcher.pattern().toString());
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature(@Arg(value = "regex", nativeType = WrapRegex.class))
public Memory skip(Environment env, Memory... args) {
  try {
    scanner.skip(args[0].toObject(WrapRegex.class).getMatcher().pattern());
    return Memory.TRUE;
  } catch (NoSuchElementException e) {
    return Memory.FALSE;
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature(@Arg(value = "pattern", nativeType = WrapRegex.class, optional = @Optional("null")))
public Memory next(Environment env, Memory... args) {
  try {
    key = key.inc();
    return current = StringMemory.valueOf(args.length == 0 || args[0].isNull()
        ? scanner.next()
        : scanner.next(args[0].toObject(WrapRegex.class).getMatcher().pattern())
    );
  } catch (NoSuchElementException e) {
    valid = false;
    current = Memory.NULL;
    key = Memory.NULL;
    return Memory.NULL;
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory __debugInfo(Environment env, Memory... args) {
  ArrayMemory r = new ArrayMemory();
  r.refOfIndex("*pattern").assign(matcher.pattern().toString());
  r.refOfIndex("*flags").assign(matcher.pattern().flags());
  r.refOfIndex("*input").assign(input);
  return r.toConstant();
}

代码示例来源:origin: jphp-group/jphp

@Signature(@Arg("string"))
public Memory with(Environment env, Memory... args) {
  Matcher matcher1 = matcher.pattern().matcher(args[0].toString());
  return new ObjectMemory(new WrapRegex(env, matcher1, args[0].toString()));
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory groupNames() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  Map<String, Integer> namedGroups = getNamedGroups(matcher.pattern());
  ArrayMemory r = new ArrayMemory();
  for (String s : namedGroups.keySet()) {
    r.put(s, StringMemory.valueOf(s));
  }
  return r.toConstant();
}

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

if (options.getMessage().isEmpty()) {
  options.getReporter().log(lineNo, MSG_REGEXP_EXCEEDED,
      matcher.pattern().toString());

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

private Matcher copyMatcher(Matcher m) {
 if (m == null)
  return m;
 else
  return m.pattern().matcher("");
}

相关文章