Class Matcher

java.lang.Object
dev.gmitch215.bytebox.regex.Matcher
All Implemented Interfaces:
MatchResult

public final class Matcher extends Object implements MatchResult
A match in progress, standing in for java.util.regex.Matcher.

The compiler substitutes java.util.regex.Matcher for this one. Finding is the platform's; the replacement syntax is not, because Java writes $1 and ${name} where the platform writes $1 and $<name>, so every replacement is assembled here rather than handed over.

What is not here, because it has no equivalent and a wrong answer would be worse than a build failure: a search region, hitEnd and requireEnd. A program reaching for one fails to compile.

Since:
1.0.0
  • Method Details

    • pattern

      public Pattern pattern()
      Returns the pattern this matches with.
      Returns:
      the pattern this matches with
    • find

      public boolean find()
      Finds the next match after where the last one ended.
      Returns:
      whether one was found
    • find

      public boolean find(int at)
      Finds the next match from a position, forgetting where the last one ended.
      Parameters:
      at - where to start
      Returns:
      whether one was found
    • matches

      public boolean matches()
      Whether the whole input matches.
      Returns:
      whether it does
    • lookingAt

      public boolean lookingAt()
      Whether the start of the input matches.
      Returns:
      whether it does
    • reset

      public Matcher reset()
      Forgets everything found so far.
      Returns:
      this matcher
    • reset

      public Matcher reset(CharSequence input)
      Forgets everything found so far and takes a new input.
      Parameters:
      input - what to search
      Returns:
      this matcher
    • group

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

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

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

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

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

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

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

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

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

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

      public Map<String,Integer> namedGroups()
      Specified by:
      namedGroups in interface MatchResult
    • results

      public Stream<MatchResult> results()
      Every match, as results that keep what they found.
      Returns:
      the matches
    • toMatchResult

      public MatchResult toMatchResult()
      Returns what was found, kept as it is now.
      Returns:
      what was found, kept as it is now
    • replaceAll

      public String replaceAll(String replacement)
      Replaces every match.
      Parameters:
      replacement - the replacement, where $1 and ${name} stand for groups
      Returns:
      the result
    • replaceFirst

      public String replaceFirst(String replacement)
      Replaces the first match.
      Parameters:
      replacement - the replacement, where $1 and ${name} stand for groups
      Returns:
      the result
    • appendReplacement

      public Matcher appendReplacement(StringBuilder into, String replacement)
      Appends everything up to the current match, then the replacement.
      Parameters:
      into - where to append
      replacement - the replacement, where $1 and ${name} stand for groups
      Returns:
      this matcher
    • appendTail

      public StringBuilder appendTail(StringBuilder into)
      Appends everything after the last match.
      Parameters:
      into - where to append
      Returns:
      what was appended to
    • quoteReplacement

      public static String quoteReplacement(String text)
      A replacement that stands for itself, with nothing in it taken as a group.
      Parameters:
      text - the replacement
      Returns:
      the escaped replacement