Class Matcher

java.lang.Object
com.codename1.util.regex.Matcher
All Implemented Interfaces:
MatchResult

public final class Matcher extends Object implements MatchResult

The same shape as java.util.regex.Matcher, over this package's Pattern.

Everything a match is read through is here -- matches, lookingAt, find, groups by number and by name, regions, and the replacement methods with the JDK's $1 and ${name} syntax. hitEnd, requireEnd and the two bounds switches are not provided.

  • Method Details

    • pattern

      public Pattern pattern()
    • usePattern

      public Matcher usePattern(Pattern newPattern)
    • reset

      public Matcher reset()
    • reset

      public Matcher reset(CharSequence input)
    • region

      public Matcher region(int start, int end)
    • regionStart

      public int regionStart()
    • regionEnd

      public int regionEnd()
    • matches

      public boolean matches()
    • lookingAt

      public boolean lookingAt()
    • find

      public boolean find()
    • find

      public boolean find(int start)
    • hasMatch

      public boolean hasMatch()
      Whether the last match operation found something.
    • start

      public int start()
      Specified by:
      start in interface MatchResult
    • start

      public int start(int group)
      Specified by:
      start in interface MatchResult
    • start

      public int start(String name)
    • end

      public int end()
      Specified by:
      end in interface MatchResult
    • end

      public int end(int group)
      Specified by:
      end in interface MatchResult
    • end

      public int end(String name)
    • group

      public String group()
      Specified by:
      group in interface MatchResult
    • group

      public String group(int group)
      Specified by:
      group in interface MatchResult
    • group

      public String group(String name)
    • groupCount

      public int groupCount()
      Specified by:
      groupCount in interface MatchResult
    • toMatchResult

      public MatchResult toMatchResult()
      The match as it is now, unaffected by what this matcher does next.
    • results

      public Stream<MatchResult> results()

      Each match from here on, as toMatchResult() would answer it: from after the last match found, or from the start of the region when there is none. The matcher is not reset, so a match already consumed is not answered again and a region stays in force.

      Lazy, as the JDK's is: each match is found only when the stream asks for it, so results().limit(1) scans no further than the first.

    • quoteReplacement

      public static String quoteReplacement(String s)
      A replacement in which $ and backslash stand for themselves.
    • appendReplacement

      public Matcher appendReplacement(StringBuilder sb, String replacement)
    • appendReplacement

      public Matcher appendReplacement(StringBuffer sb, String replacement)
    • appendTail

      public StringBuilder appendTail(StringBuilder sb)
    • appendTail

      public StringBuffer appendTail(StringBuffer sb)
    • replaceAll

      public String replaceAll(String replacement)
    • replaceAll

      public String replaceAll(Function<MatchResult, String> replacer)
    • replaceFirst

      public String replaceFirst(String replacement)
    • replaceFirst

      public String replaceFirst(Function<MatchResult, String> replacer)
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object