Interface Matcher

All Superinterfaces:
Matcher, MatchResult

public interface Matcher extends Matcher
Adds some "advanced" methods to the Matcher interface.
  • Method Details

    • compileReplacement

      Matcher.CompiledReplacement compileReplacement(String replacement)
      Pre-compiles a replacement string for later use by Matcher.appendReplacement(Appendable, String), Matcher.replaceAll(String) and Matcher.replaceFirst(String).

      Supports the following JRE6-compatible constructs:

      \x
      x
      The character x, literally.
      $n
      The value of the nth capturing group, or "" if that group is not set.

      Supports the following JRE7-compatible constructs:

      ${name}
      The value of the named capturing group "name", or "" if that group is not set.

      Supports the following additional constructs:

      ${expression}
      The value of the expression. The named groups of the pattern are available as expression variables; the matcher is available as variable "m". For the expression syntax, see Parser.
    • count

      int count(int number)
      Returns, after a successful match, the value of the designated "capturing quantifier". A "capturing quantifier" has the form "{m,n}", where the comma and n are optional.

      Capturing quantifier numbers start at zero, and increase left-to-right.

      Example:

      The regex is "a{1,}b{1,}c{1,}", the subject string is " abc aabbcc abbccc ". There are three matches, and count(int) returns the following values:

      Match #count(0)count(1)count(2)
      1111
      2222
      3123

      The return value is undefined if there was no previous match, or if the quantifier was not executed during the match.

    • quoteReplacement

      String quoteReplacement(String s)
      Specified by:
      quoteReplacement in interface Matcher
      See Also: