Class Catalog

java.lang.Object
aQute.libg.re.Catalog

public class Catalog extends Object
This class provides an implementation of the RE types. The class is useful as static imports. (For Eclipse users, look at favorites in the preferences.) However, it can also be used as base class. If that is the case, field names can be used as named capture groups. In this constellation, the static methods are also in scope, not requiring many static imports.
void foo() {
        class X extends Catalog {
                RE match = lit("abc");
                RE namedMatch = named(match);
        }
        X x;
 x.....
}
  • Field Details

    • ws

      public static final RE.C ws
    • setWs

      public static final RE.Q setWs
    • someWs

      public static final RE.Q someWs
    • all

      public static final RE all
    • setAll

      public static final RE.Q setAll
    • someAll

      public static final RE someAll
    • backslash

      public static final RE.C backslash
    • Lu

      public static final RE.C Lu
    • Ll

      public static final RE.C Ll
    • Lt

      public static final RE.C Lt
    • Lm

      public static final RE.C Lm
    • Lo

      public static final RE.C Lo
    • Nd

      public static final RE.C Nd
    • Nl

      public static final RE.C Nl
    • No

      public static final RE.C No
    • Z

      public static final RE.C Z
    • P

      public static final RE.C P
    • S

      public static final RE.C S
    • Cc

      public static final RE.C Cc
    • Cf

      public static final RE.C Cf
    • Cn

      public static final RE.C Cn
    • Lower

      public static final RE.C Lower
    • Upper

      public static final RE.C Upper
    • ASCII

      public static final RE.C ASCII
    • Alpha

      public static final RE.C Alpha
    • Digit

      public static final RE.C Digit
    • Alnum

      public static final RE.C Alnum
    • Punct

      public static final RE.C Punct
    • Graph

      public static final RE.C Graph
    • Print

      public static final RE.C Print
    • Blank

      public static final RE.C Blank
    • Cntrl

      public static final RE.C Cntrl
    • XDigit

      public static final RE.C XDigit
    • Space

      public static final RE.C Space
    • letter

      public static final RE.C letter
    • dollar

      public static final RE.C dollar
    • euro

      public static final RE.C euro
    • word

      public static final RE.Q word
    • digit

      public static final RE.C digit
    • nonDigit

      public static final RE.C nonDigit
    • lineEnd

      public static final RE.C lineEnd
    • dot

      public static final RE.C dot
    • comma

      public static final RE.C comma
    • semicolon

      public static final RE.C semicolon
    • colon

      public static final RE.C colon
    • nl

      public static final RE.C nl
    • cr

      public static final RE.C cr
    • lf

      public static final RE.C lf
    • ff

      public static final RE.C ff
    • alarm

      public static final RE.C alarm
    • escape

      public static final RE.C escape
    • eof

      public static final RE eof
    • eol

      public static final RE eol
    • parOpen

      public static final RE.C parOpen
    • parClose

      public static final RE.C parClose
    • empty

      public static final RE empty
    • tab

      public static final RE.C tab
    • number

      public static final RE number
    • hexdigit

      public static RE.C hexdigit
    • bindigit

      public static RE.C bindigit
    • hexnumber

      public static RE hexnumber
    • minus

      public static final RE.C minus
    • dquote

      public static final RE.C dquote
    • squote

      public static final RE.C squote
    • backQuote

      public static final RE.C backQuote
    • underscore

      public static final RE.C underscore
    • qualifier

      public static final RE.Q qualifier
    • version

      public static final RE version
    • javaLowerCase

      public static final RE.C javaLowerCase
    • javaUpperCase

      public static final RE.C javaUpperCase
    • javaWhitespace

      public static final RE.C javaWhitespace
    • javaMirrored

      public static final RE.C javaMirrored
    • javaJavaIdentifierStart

      public static final RE.C javaJavaIdentifierStart
    • javaJavaIdentifierPart

      public static final RE.C javaJavaIdentifierPart
    • javaId

      public static final RE javaId
    • fullyQualifiedName

      public static final RE fullyQualifiedName
    • startOfLine

      public static final RE startOfLine
    • endOfLine

      public static final RE endOfLine
    • wordBoundary

      public static final RE wordBoundary
    • beginInput

      public static final RE beginInput
    • endOfPreviousMatch

      public static final RE endOfPreviousMatch
    • endOfInputForFinal

      public static final RE endOfInputForFinal
    • endOfInput

      public static final RE endOfInput
    • isLatin

      public static final RE.C isLatin
    • inGreek

      public static final RE.C inGreek
    • isAlphabetic

      public static final RE.C isAlphabetic
    • sc

      public static final RE.C sc
  • Constructor Details

    • Catalog

      public Catalog()
  • Method Details

    • named

      public RE named(RE re)
      If this class is extended, the named fields in that class can be used in named groups. This method will lookup the name of a field and create a capturing group with this name. It finds the field by comparing the content.
      Parameters:
      re - the RE that should be in a field in this class.
      Returns:
      a group RE
    • control

      public static RE control(char c)
      Return a control char. For example, `control('b') returns ^b. See the sequence `\\cb`.
      Parameters:
      c - the control character
      Returns:
      an RE representing the control character
    • g

      public static RE g(RE... res)
      Create a non capturing group
      Parameters:
      res - the members
      Returns:
      a non capturing group
    • or

      public static RE or(RE... res)
      Create an OR combination of a number of RE's
      Parameters:
      res - the set of RE's that are the members of the OR
      Returns:
      the RE representing the OR
    • or

      public static RE or(String... res)
      Create an OR combination of a number of Strings. The strings are converted with lit(String).
      Parameters:
      res - the strings
      Returns:
      the RE representing the OR
    • or

      public static RE or(RE.C... res)
      Create an or combination of character classes.
      Parameters:
      res - the character classes
      Returns:
      an RE representing the combined clases
    • g

      public static RE g(String name, RE... res)
      Create a named capturing group
      Parameters:
      name - the name of the group. This must be a valid Java identifier
      res - the members.
      Returns:
      a new named capture group
    • term

      public static RE term(String name, RE... res)
      Return a named group but where each member that is not a whitespace, will be preceded with a #setWs.
      Parameters:
      name - the name of the group or null for a non-named group
      res - the members
      Returns:
      a group, either named or capturing
    • term

      public static RE term(RE... res)
      See term(String,RE...) with a null for name
      Parameters:
      res - the members
      Returns:
      a new
    • cc

      public static RE.C cc(String allowed)
      Create a character class. I.e. `[abc]`. Do not include the ^ to negate the set, use the not() method.
      Parameters:
      allowed - the allowed characters
      Returns:
      a character class.
    • lit

      public static RE lit(String s)
      Provide a literal text. This lit can contain characters that normally have a special meaning. All characters that have a special meaning are escaped with the backslash ('\').
      Parameters:
      s - the literal string
      Returns:
      an RE
    • lit

      public static RE[] lit(String... s)
      Useful if you need a number of literal REs
      Parameters:
      s - the strings
      Returns:
      an array of RE
    • quote

      public static RE quote(String s)
      Use the quoting facility built into Pattern.quote(String)
      Parameters:
      s - the string
      Returns:
      the quoted string
    • unicode

      public static RE unicode(String name)
      Use the Unicode name. Is \\N
      Parameters:
      name - the unicode name.
      Returns:
      the RE representing the unicode name.
    • back

      public static RE back(int group)
      Used to reference a previous capturing group. Unfortunately this cannot be done by name. This class will by default create non-capturing groups, so only explicit groups need to be counted.
      Parameters:
      group - the group number
      Returns:
      a new RE referencing a previous group
    • back

      public static RE back(String group)
      Used to reference a previous named capturing group.
      Parameters:
      group - the group name
      Returns:
      a new RE referencing a previous group
    • list

      public static RE list(RE clause, RE separator)
      Create a list of clauses separated by a separator. The clauses and separators will be separated by zero or more whitespace.
      Parameters:
      clause -
      separator -
      Returns:
      a new RE that presents a list of clauses
    • list

      public static RE list(RE clause)
      Create a list of clauses separated by a comma. The clauses and separators will be separated by zero or more whitespace.
      Parameters:
      clause -
      Returns:
      a new RE that presents a list of clauses separated by commas
    • opt

      public static RE.Q opt(RE... res)
      Return an optional RE
      Parameters:
      res - the members of the optional
      Returns:
      a Q representing the optional
    • opt

      public static RE.Q opt(String s)
      Return an optional literal (see lit(String)t
      Parameters:
      s - the literal
      Returns:
      a Q representing the optional
    • some

      public static RE.Q some(RE... res)
      Return a group of some members.
      Parameters:
      res - the members
      Returns:
      a Q representing the some
    • set

      public static RE.Q set(RE... res)
      Return a group of some members.
      Parameters:
      res - the members
      Returns:
      a Q representing the some
    • not

      public static RE not(RE re)
      Creates a regular expression that matches the negation of the provided regular expression. This method wraps the given regex pattern in a negative construct.
      Parameters:
      re - the regular expression to be negated
      Returns:
      a new RE instance representing the negated version of the provided regular expression
    • reluctant

      public static RE reluctant(RE.Q re)
      Modifies the given quantified regular expression to match reluctantly. A reluctant quantifier matches as few characters as possible.
      Parameters:
      re - the quantified regular expression to be modified
      Returns:
      a new RE instance with a reluctant quantification
    • greedy

      public static RE greedy(RE.Q re)
      Modifies the given quantified regular expression to match greedily. A greedy quantifier matches as many characters as possible.
      Parameters:
      re - the quantified regular expression to be modified
      Returns:
      a new RE instance with a greedy quantification
    • possesive

      public static RE possesive(RE.Q re)
      Modifies the given quantified regular expression to match in a possessive manner. A possessive quantifier does not give up matches as the regex engine backtracks.
      Parameters:
      re - the quantified regular expression to be modified
      Returns:
      a new RE instance with a possessive quantification
    • anythingBut

      public static RE anythingBut(String s)
      Creates a regular expression that matches anything except the specified string. For a single character, it creates a negated character class; otherwise, it negates the literal string.
      Parameters:
      s - the string to be negated in the match
      Returns:
      an RE instance that matches anything but the specified string
    • maybe

      public static RE maybe(String s)
      Creates a regular expression that optionally matches the given string. The string is wrapped in a non-capturing group with a quantifier allowing zero or one occurrence.
      Parameters:
      s - the string to be optionally matched
      Returns:
      an RE instance that optionally matches the specified string
    • multiple

      public static RE.Q multiple(int minimum, int maximum, RE... res)
      Creates a quantified regular expression that matches a specified minimum and maximum number of occurrences. This method applies a greedy quantifier.
      Parameters:
      minimum - the minimum number of occurrences to match
      maximum - the maximum number of occurrences to match
      res - the regular expressions to be quantified
      Returns:
      a Q instance representing the specified quantification
    • multiple

      public static RE.Q multiple(int minimum, int maximum, String lit)
      Creates a quantified regular expression that matches a specified minimum and maximum number of occurrences of a literal string. This method applies a greedy quantifier.
      Parameters:
      minimum - the minimum number of occurrences to match
      maximum - the maximum number of occurrences to match
      lit - the literal string to be quantified
      Returns:
      a Q instance representing the specified quantification of the literal string
    • atLeast

      public static RE.Q atLeast(int minimum, RE... res)
      Creates a quantified regular expression that matches at least a specified minimum number of occurrences. This method applies a greedy quantifier.
      Parameters:
      minimum - the minimum number of occurrences to match
      res - the regular expressions to be quantified
      Returns:
      a Q instance representing the quantification with the specified minimum and no maximum limit
    • atLeast

      public static RE.Q atLeast(int minimum, String lit)
      Creates a quantified regular expression that matches at least a specified minimum number of occurrences of a literal string. This method applies a greedy quantifier.
      Parameters:
      minimum - the minimum number of occurrences to match
      lit - the literal string to be quantified
      Returns:
      a Q instance representing the quantification with the specified minimum and no maximum limit
    • caseInsenstive

      public static RE.F caseInsenstive(RE... res)
      Applies the case-insensitive flag to the provided regular expressions. This method makes the given patterns match characters regardless of their case.
      Parameters:
      res - the regular expressions to be affected by the case-insensitive flag
      Returns:
      an F instance with the case-insensitive flag applied
    • caseInsenstiveOff

      public static RE.F caseInsenstiveOff(RE... res)
      Turns off the case-insensitive flag for the provided regular expressions. This method reverts the given patterns to match characters considering their case.
      Parameters:
      res - the regular expressions to be affected by turning off the case-insensitive flag
      Returns:
      an F instance with the case-insensitive flag turned off
    • dotall

      public static RE.F dotall(RE... res)
      Applies the dotall flag to the provided regular expressions. With this flag, the dot ('.') pattern matches any character, including a line terminator.
      Parameters:
      res - the regular expressions to be affected by the dotall flag
      Returns:
      an F instance with the dotall flag applied
    • dotallOff

      public static RE.F dotallOff(RE... res)
      Turns off the dotall flag for the provided regular expressions. With the flag turned off, the dot ('.') pattern does not match line terminators by default.
      Parameters:
      res - the regular expressions to be affected by turning off the dotall flag
      Returns:
      an F instance with the dotall flag turned off
    • comments

      public static RE.F comments(RE... res)
      Applies the comments flag to the provided regular expressions. This flag allows whitespace and comments within the pattern for better readability.
      Parameters:
      res - the regular expressions to be affected by the comments flag
      Returns:
      an F instance with the comments flag applied
    • commentsOff

      public static RE.F commentsOff(RE... res)
      Turns off the comments flag for the provided regular expressions. With the flag turned off, whitespace and comments within the pattern are no longer ignored.
      Parameters:
      res - the regular expressions to be affected by turning off the comments flag
      Returns:
      an F instance with the comments flag turned off
    • multiline

      public static RE.F multiline(RE... res)
      Applies the multiline flag to the provided regular expressions. This flag changes the behavior of '^' and '$' from matching at the start and end of the input string to matching at the start and end of each line.
      Parameters:
      res - the regular expressions to be affected by the multiline flag
      Returns:
      an F instance with the multiline flag applied
    • multilineOff

      public static RE.F multilineOff(RE... res)
      Turns off the multiline flag for the provided regular expressions. With the flag turned off, '^' and '$' match only at the start and end of the entire input string.
      Parameters:
      res - the regular expressions to be affected by turning off the multiline flag
      Returns:
      an F instance with the multiline flag turned off
    • unicodeCharacterClass

      public static RE.F unicodeCharacterClass(RE... res)
      Applies the unicode character class flag to the provided regular expressions. This flag enables the Unicode versions of predefined character classes and POSIX character classes.
      Parameters:
      res - the regular expressions to be affected by the unicode character class flag
      Returns:
      an F instance with the unicode character class flag applied
    • unicodeCharacterClassOff

      public static RE.F unicodeCharacterClassOff(RE... res)
      Turns off the unicode character class flag for the provided regular expressions. With the flag turned off, the ASCII versions of predefined character classes and POSIX character classes are used.
      Parameters:
      res - the regular expressions to be affected by turning off the unicode character class flag
      Returns:
      an F instance with the unicode character class flag turned off
    • unicodeCase

      public static RE.F unicodeCase(RE... res)
      Applies the unicode case flag to the provided regular expressions. This flag enables the correct handling of character cases in Unicode when applying case-insensitive matching.
      Parameters:
      res - the regular expressions to be affected by the unicode case flag
      Returns:
      an F instance with the unicode case flag applied
    • unicodeCaseOff

      public static RE.F unicodeCaseOff(RE... res)
      Turns off the unicode case flag for the provided regular expressions. With the flag turned off, character cases in Unicode are not correctly handled when applying case-insensitive matching.
      Parameters:
      res - the regular expressions to be affected by turning off the unicode case flag
      Returns:
      an F instance with the unicode case flag turned off
    • unixLines

      public static RE.F unixLines(RE... res)
      Applies the unix lines flag to the provided regular expressions. This flag affects how line terminators are matched. With this flag, only the '\n' line terminator is recognized.
      Parameters:
      res - the regular expressions to be affected by the unix lines flag
      Returns:
      an F instance with the unix lines flag applied
    • unixLinesOff

      public static RE.F unixLinesOff(RE... res)
      Turns off the unix lines flag for the provided regular expressions. With the flag turned off, line terminators are matched in a platform-independent manner.
      Parameters:
      res - the regular expressions to be affected by turning off the unix lines flag
      Returns:
      an F instance with the unix lines flag turned off
    • atomic

      public static RE.G atomic(RE... res)
      Combine the res into a single atomic Group.
      Parameters:
      res - the constituents.
      See Also:
    • atomic

      public static RE.G atomic(String string)
      Creates an atomic group with the provided string. An atomic group prevents the regex engine from backtracking once the group has matched.
      Parameters:
      string - the literal string to be included in the atomic group
      Returns:
      a G instance representing an atomic group containing the provided string
    • ahead

      public static RE.G ahead(RE... res)
      Creates a lookahead group with the provided regular expressions. A lookahead group asserts that the given pattern must be matched next in the input sequence.
      Parameters:
      res - the regular expressions to be included in the lookahead group
      Returns:
      a G instance representing a lookahead group containing the provided expressions
    • behind

      public static RE.G behind(RE... res)
      Creates a lookbehind group with the provided regular expressions. A lookbehind group asserts that the given pattern must precede the current position in the input sequence.
      Parameters:
      res - the regular expressions to be included in the lookbehind group
      Returns:
      a G instance representing a lookbehind group containing the provided expressions
    • seq

      public static RE.G seq(RE... res)
      Creates a sequence of regular expressions. This method groups the provided expressions in the order they are given, without any additional logic.
      Parameters:
      res - the regular expressions to be sequenced
      Returns:
      a G instance representing a sequence of the provided regular expressions
    • if_

      public static RE if_(RE condition, RE thenExpect, RE otherWiseExpect)
      Creates a conditional regular expression. The resulting pattern matches 'thenExpect' if 'condition' matches, otherwise it matches 'otherWiseExpect'.
      Parameters:
      condition - the conditional regular expression
      thenExpect - the regular expression to match if the condition is true
      otherWiseExpect - the regular expression to match if the condition is false
      Returns:
      an RE instance representing the conditional regular expression
    • if_

      public static RE if_(RE condition, RE then)
      Creates a conditional regular expression with no alternative case. The resulting pattern matches 'then' only if 'condition' matches.
      Parameters:
      condition - the conditional regular expression
      then - the regular expression to match if the condition is true
      Returns:
      an RE instance representing the conditional regular expression with no alternative case
    • while_

      public static RE while_(RE condition, RE thenExpect)
      Creates a regular expression that repeats the 'thenExpect' pattern as long as 'condition' matches.
      Parameters:
      condition - the condition for repetition
      thenExpect - the regular expression to be repeated
      Returns:
      an RE instance representing the repeated regular expression
    • until

      public static RE until(RE condition, RE thenExpect)
      Creates a regular expression that matches 'thenExpect' until 'condition' becomes true.
      Parameters:
      condition - the condition to terminate matching
      thenExpect - the regular expression to match until the condition is met
      Returns:
      an RE instance representing the regular expression matching until the condition
    • capture

      public static RE.G capture(RE... res)
      Creates a capturing group with the provided regular expressions. This method groups the expressions and captures them for later reference.
      Parameters:
      res - the regular expressions to be included in the capturing group
      Returns:
      a G instance representing a capturing group containing the provided expressions
    • string

      public static RE string(char delimeter)
      Return a string that is delimeted on both sides with the same character. The character cannot be used directly but must be escaped with a backslash.
    • re

      public static RE re(String regex)