Class RegExpApi

java.lang.Object
org.rekex.regexp.RegExpApi

public class RegExpApi extends Object
This class contains static factory methods to create and transform regular expressions, using data structure of RegExp.

For convenience, many methods, like seq(Object...), accept `Object` as arguments, which are automatically converted to `RegExp`. `Character` or `Integer` is converted to a single character. `String` is converted to a sequence of single characters.

In addition, some methods, like intersect(Object...), expect arguments to be character classes; automatic conversion will be attempted, e.g. to convert `alt(cc1,cc2)` to `union(cc1,cc2)`, and `seq(cc1)` to `cc1`.

For opt(Object...), rep0(Object...), rep1(Object...), multiple arguments will be interpreted as a sequence, e.g. `opt(r1, r2)` is equivalent to `opt(seq(r1, r2))`.

  • Constructor Details

    • RegExpApi

      public RegExpApi()
  • Method Details

    • ch

      public static RegExp.CharClass ch(String chars)
      A character class that contains all code points in `chars`.
    • range

      public static RegExp.CharClass.Range range(int from, int to)
      A character class with characters in [from-to], inclusive.
    • predefined

      public static RegExp.CharClass.Predefined predefined(String regex)
      A predefined character class, e.g. `predefined("\\d")`.
    • union

      public static RegExp.CharClass union(Object... args)
      Union of character classes. Each `arg` must be convertible to a character class.
    • intersect

      public static RegExp.CharClass intersect(Object... args)
      Intersection of character classes. Each `arg` must be convertible to a character class.
    • negate

      public static RegExp.CharClass negate(Object arg)
      Negation of a character classes. The `arg` must be convertible to a character class.
    • seq

      public static RegExp seq(Object... args)
      Concatenation of subexpressions.
    • alt

      public static RegExp alt(Object... args)
      Alternation of subexpressions.
    • opt

      public static RegExp.Quantified opt(Object... sequence)
      Optional, i.e. X?
    • rep0

      public static RegExp.Quantified rep0(Object... sequence)
      Repeat 0 or more times, i.e. X*
    • rep1

      public static RegExp.Quantified rep1(Object... sequence)
      Repeat 1 or more times, i.e. X+
    • times

      public static RegExp.Quantified times(int n, RegExp exp)
      Repeat exactly `n` times
    • times

      public static RegExp.Quantified times(int min, long max, RegExp exp)
      Repeat `min` to `max` times, inclusive. Set `max=Long.MAX_VALUE` as infinity.
    • reluctant

      public static RegExp.Quantified reluctant(RegExp.Quantified q)
      Reluctant quantifier
    • possessive

      public static RegExp.Quantified possessive(RegExp.Quantified q)
      Possessive quantifier
    • group

      public static RegExp.Group.Unnamed group(RegExp arg)
      An un-named group
    • group

      public static RegExp.Group.Named group(String name, RegExp arg)
      A named group
    • atomicGroup

      public static RegExp.AtomicGroup atomicGroup(RegExp arg)
      An atomic group
    • backRef

      public static RegExp.BackReference.WithName backRef(String name)
      Back reference with a group name
    • backRef

      public static RegExp.BackReference.WithName backRef(RegExp.Group.Named namedGroup)
      Back reference to a named group
    • backRef

      public static RegExp.BackReference.WithNumber backRef(int number)
      Back reference with a group number
    • flag

      public static RegExp.Flagged flag(boolean on, int flags, RegExp arg)
      Turn flags on/off
    • ignoreCase

      public static RegExp.Flagged ignoreCase(RegExp arg)
      Turn on the flag CASE_INSENSITIVE
    • boundary

      public static RegExp.Boundary boundary(String regex)
      A boundary matcher, e.g. `boundary("\\b{g}")`.
    • boundary_beginning_of_line

      public static RegExp.Boundary boundary_beginning_of_line()
      Same as `boundary("^")`
    • boundary_end_of_line

      public static RegExp.Boundary boundary_end_of_line()
      Same as `boundary("$")`
    • boundary_word_boundary

      public static RegExp.Boundary boundary_word_boundary()
      Same as `boundary("\\b")`
    • boundary_non_word_boundary

      public static RegExp.Boundary boundary_non_word_boundary()
      Same as `boundary("\\B")`
    • boundary_beginning_of_input

      public static RegExp.Boundary boundary_beginning_of_input()
      Same as `boundary("\\A")`
    • boundary_end_of_previous_match

      public static RegExp.Boundary boundary_end_of_previous_match()
      Same as `boundary("\\G")`
    • boundary_end_of_input_but_for_final_terminator

      public static RegExp.Boundary boundary_end_of_input_but_for_final_terminator()
      Same as `boundary("\\Z")`
    • boundary_end_of_input

      public static RegExp.Boundary boundary_end_of_input()
      Same as `boundary("\\z")`
    • lookahead

      public static RegExp.Lookaround lookahead(boolean positive, RegExp arg)
      A lookahead, positive or negative
    • lookbehind

      public static RegExp.Lookaround lookbehind(boolean positive, RegExp arg)
      A lookbehind, positive or negative
    • opaque

      public static RegExp.Opaque opaque(String regex)
      An opaque regex
    • simplify

      public static RegExp simplify(RegExp exp)
      Perform some simplifications to the regular expression
    • toRegex

      public static String toRegex(RegExp exp)
      Return the typical string representation of the regular expression.
    • toTreeText

      public static String toTreeText(RegExp exp)
      Return a multiline text that displays the tree structure of the regular expression.
    • findGroupNumberIn

      public static int findGroupNumberIn(RegExp.Group group, RegExp exp)
      Find the group number of `group` in `exp`; return -1 if not found.