Interface RE

All Known Subinterfaces:
RE.C, RE.F, RE.G, RE.Q

public interface RE
A library to make regular expressions with Pattern a bit easier to use. The Pattern class is extremely powerfull and as far as I know high performance. However,regular expressions quickly become unwieldy.

This class provides a more modern interface using lambdas and options and the accompanying Catalog class provides a comprehensive set of constants and static methods to create complex regular expressions.

  • Method Details

    • asFindPredicate

      Predicate<String> asFindPredicate()
      Return a predicate that checks if the pattern is found in the tested string.
    • asLookingAtPredicate

      Predicate<String> asLookingAtPredicate()
      Return a predicate that checks if the pattern is looking at in the tested string.
    • asMatchPredicate

      Predicate<String> asMatchPredicate()
      Return a predicate that checks if the pattern is matched at in the tested string.
    • findIn

      Optional<RE.Match> findIn(String string)
      Find the given pattern in the given string. If found, a Match is returned that can be used to continue.
      Parameters:
      string - the source string
      Returns:
      a matcher if found
    • findAllIn

      Stream<RE.Match> findAllIn(String string)
      Return a stream with matches in the current string
      Parameters:
      string - the source string
    • append

      default String append(String string, Function<RE.Match,String> replacement)
      Return
      Parameters:
      string - the source string
      Returns:
      the replaced String
    • append

      void append(StringBuilder sb, String string, Function<RE.Match,String> replacement)
      Append the StringBuilder by finding all this matches in the given string, and using the replacement from the replacement function. For each match, this function is called with the Match. The function can then take the captured groups and calculate the replacement string. This is like a template function.

      If the replacement function returns null, it will be ignored

      Parameters:
      sb - the builder
      string - the source string
      replacement -
    • getGroupNames

      Set<String> getGroupNames()
      Get a set of group names in the current RE. This includes any member REs recursively.
    • isMatch

      boolean isMatch(String string)
      Returns true if this RE matches the given string.
      Parameters:
      string - the source string
    • isSingle

      boolean isSingle()
      Returns true if this RE is a single node. That is a single letter, a character class, a group that is not NONE, etc.
    • lookingAt

      Optional<RE.Match> lookingAt(String string)
      Match with lookingAt
      Parameters:
      string - the source string
    • getMatcher

      Matcher getMatcher(CharSequence string)
      Get a new matcher activated with the given source string.
      Parameters:
      string - the source string
    • matches

      Optional<RE.Match> matches(String string)
      Matches the source string to this RE. If there is a match, it returns the Match
      Parameters:
      string - the source string
    • merge

      Optional<RE> merge(RE re)
      Merge another RE with this RE. This is not always possible.
      Parameters:
      re - the other RE
    • not

      RE not()
      Reverse the meaning of this RE. This depends on the different types. If it has no meaning, it will return the original.
    • toString

      String toString()
      Overrides:
      toString in class Object
    • pattern

      Pattern pattern(RE.F.Flag... flags)
      Return the pattern compiled with the given flags. The pattern is cached for optimization but this method can be called concurrently.
      Parameters:
      flags - the flags