Class Re


  • public final class Re
    extends Object

    Commonly used Regex classes and constructs for building Patterns.

    Author:
    David B. Bracewell
    • Method Detail

      • any

        public static String any()
        Any string.
        Returns:
        the string
      • chars

        public static String chars​(boolean negated,
                                   @NonNull
                                   @NonNull CharSequence... chars)
        Converts the given array of strings into a regex character class.
        Parameters:
        negated - True if the class should be negated.
        chars - the components of the character class
        Returns:
        the character class
      • chars

        public static String chars​(boolean negated,
                                   @NonNull
                                   @lombok.NonNull char... chars)
        Converts the given array of characters into a regex character class.
        Parameters:
        negated - True if the class should be negated.
        chars - the components of the character class
        Returns:
        the character class
      • chars

        public static String chars​(String... chars)
        Converts the given array of strings into a regex character class.
        Parameters:
        chars - the components of the character class
        Returns:
        the character class
      • chars

        public static String chars​(char... chars)
        Converts the given array of chars into a regex character class.
        Parameters:
        chars - the components of the character class
        Returns:
        the character class
      • e

        public static String e​(char character)
        E string.
        Parameters:
        character - the character
        Returns:
        the string
      • greedyOneOrMore

        public static String greedyOneOrMore​(@NonNull
                                             @NonNull CharSequence... sequence)
        Greedy one or more string.
        Parameters:
        sequence - the sequence
        Returns:
        the string
      • greedyZeroOrMore

        public static String greedyZeroOrMore​(@NonNull
                                              @NonNull CharSequence... sequence)
        Greedy zero or more string.
        Parameters:
        sequence - the sequence
        Returns:
        the string
      • group

        public static String group​(@NonNull
                                   @NonNull CharSequence... sequence)
        Group string.
        Parameters:
        sequence - the sequence
        Returns:
        the string
      • line

        public static String line​(@NonNull
                                  @NonNull CharSequence... patterns)
        Generates a regular expression to match the entire line, i.e. ^pattern$
        Parameters:
        patterns - The patterns making up the line
        Returns:
        The regluar expresion
      • max

        public static String max​(int max,
                                 @NonNull
                                 @NonNull CharSequence... sequence)
        Max string.
        Parameters:
        max - the max
        sequence - the sequence
        Returns:
        the string
      • min

        public static String min​(int min,
                                 @NonNull
                                 @NonNull CharSequence... sequence)
        Min string.
        Parameters:
        min - the min
        sequence - the sequence
        Returns:
        the string
      • namedGroup

        public static String namedGroup​(@NonNull
                                        @NonNull CharSequence groupName,
                                        @NonNull
                                        @NonNull CharSequence... regex)
        Defines the given regex as a named match group.
        Parameters:
        groupName - the group name
        regex - the regex
        Returns:
        the named match group
      • negLookahead

        public static String negLookahead​(@NonNull
                                          @NonNull CharSequence... regex)
        Defines a negative lookahead for the given regex.
        Parameters:
        regex - the regex
        Returns:
        the regex
      • negLookbehind

        public static String negLookbehind​(@NonNull
                                           @NonNull CharSequence... regex)
        Defines a negative non-consuming lookahead for the given regex.
        Parameters:
        regex - the regex
        Returns:
        the regex
      • next

        public static String next​(Matcher m)
        Next string.
        Parameters:
        m - the m
        Returns:
        the string
      • nonMatchingGroup

        public static String nonMatchingGroup​(@NonNull
                                              @NonNull CharSequence... regex)
        Defines the given regex as a non-matching group
        Parameters:
        regex - the regex
        Returns:
        the non-matching group
      • notChars

        public static String notChars​(CharSequence... chars)
        Converts the given array of strings into a negated regex character class.
        Parameters:
        chars - the components of the character class
        Returns:
        the negated character class
      • notChars

        public static String notChars​(char... chars)
        Converts the given array of strings into a negated regex character class.
        Parameters:
        chars - the components of the character class
        Returns:
        the negated character class
      • oneOrMore

        public static String oneOrMore​(@NonNull
                                       @NonNull CharSequence... sequence)
        One or more string.
        Parameters:
        sequence - the sequence
        Returns:
        the string
      • or

        public static String or​(@NonNull
                                @NonNull CharSequence... sequence)
        Combines the given regex patterns as alternations. Should be wrapped as a group.
        Parameters:
        sequence - the regex
        Returns:
        the alternation
      • posLookahead

        public static String posLookahead​(@NonNull
                                          @NonNull CharSequence... regex)
        Defines a positive lookahead for the given regex.
        Parameters:
        regex - the regex
        Returns:
        the regex
      • posLookbehind

        public static String posLookbehind​(@NonNull
                                           @NonNull CharSequence... regex)
        Defines a non-consuming positive lookahead for the given regex.
        Parameters:
        regex - the regex
        Returns:
        the regex
      • q

        public static String q​(@NonNull
                               @NonNull CharSequence pattern)
        Q string.
        Parameters:
        pattern - the pattern
        Returns:
        the string
      • r

        public static Pattern r​(int flags,
                                @NonNull
                                @NonNull CharSequence... patterns)
        Compiles the given patterns, treating them as a sequence, with the given flags.
        Parameters:
        flags - the flags
        patterns - the patterns
        Returns:
        the pattern
      • r

        public static Pattern r​(@NonNull
                                @NonNull CharSequence... patterns)
        Compiles the given patterns, treating them as a sequence.
        Parameters:
        patterns - the patterns
        Returns:
        the pattern
      • range

        public static String range​(int min,
                                   int max,
                                   @NonNull
                                   @NonNull CharSequence... sequence)
        Range string.
        Parameters:
        min - the min
        max - the max
        sequence - the sequence
        Returns:
        the string
      • re

        public static String re​(@NonNull
                                @NonNull CharSequence... sequence)
        Combines the given regex patterns into a sequence.
        Parameters:
        sequence - the regex
        Returns:
        the string
      • zeroOrMore

        public static String zeroOrMore​(@NonNull
                                        @NonNull CharSequence... sequence)
        Zero or more string.
        Parameters:
        sequence - the sequence
        Returns:
        the string
      • zeroOrOne

        public static String zeroOrOne​(@NonNull
                                       @NonNull CharSequence... sequence)
        Zero or one string.
        Parameters:
        sequence - the sequence
        Returns:
        the string