public abstract class Pattern extends java.lang.Object implements Matchable
Methods are provided here for building up patterns from smaller ones, like regular expressions.
The regex(String)
, regexI(String)
, thenRegex(String)
,
and thenRegexI(String)
methods can be used to parse regular expression
syntax into patterns. See RegexParser
for syntax information
In DFALex, the only requirement for a pattern is that it can add itself to an
Nfa
so we can make matchers with it.
Modifier and Type | Field and Description |
---|---|
static Pattern |
ALL_STRINGS
Pattern that matches all strings
|
static Pattern |
BLOCK_COMMENT
Typical Java/C/CSS - style block comment
|
static Pattern |
DECIMAL
A
FLOAT_DECIMAL or an INTEGER . |
static Pattern |
DIGITS
Pattern that matches one or more decimal digits
|
static Pattern |
DQ_STRING
double-quoted string with backslash escapes and no carriage returns or newlines
|
static Pattern |
EMPTY
Pattern that matches only the empty string
|
static Pattern |
FLOAT_DECIMAL
A decimal number that includes a decimal point and/or scientific exponent, and does NOT match
INTEGER . |
static Pattern |
HEXDIGITS
Pattern that matches one or more hexadecimal digits
|
static Pattern |
INTEGER
Pattern that matches an optional sign, followed by one or more decimal digits
|
static Pattern |
LINE_COMMENT
Typical Java/C++ - style line comment
note that this doesn't include the newline.
|
static Pattern |
SIMPLE_DECIMAL
A pattern that matches an
INTEGER , optionally followed by a '.' and zero or more digits |
static Pattern |
SQ_STRING
single-quoted string with backslash escapes and no carriage returns or newlines
|
static Pattern |
STRING
single or double-quoted string with backslash escapes and no carriage returns or newlines
|
Constructor and Description |
---|
Pattern() |
Modifier and Type | Method and Description |
---|---|
static Pattern |
anyCharIn(java.lang.String chars)
Create a pattern that matches any single character from the given string
|
static Pattern |
anyOf(java.util.Collection<? extends Matchable> patterns)
Create a pattern that matches any of the given patterns
|
static Pattern |
anyOf(Matchable... patterns)
Create a pattern that matches any of the given patterns
|
static Pattern |
anyOf(java.lang.String p0,
java.lang.String p1,
java.lang.String... strings)
Create a pattern that matches any of the given strings
|
static Pattern |
anyOfI(java.lang.String p0,
java.lang.String p1,
java.lang.String... strings)
Create a pattern that matches any of the given strings, case independent
|
Matchable |
getReversed()
Get the reverse of this pattern
|
static Pattern |
match(Matchable tomatch)
|
static Pattern |
match(java.lang.String tomatch)
Create a pattern that exactly matches a single string, case-dependent
|
static Pattern |
matchI(java.lang.String tomatch)
Create a pattern that exactly matches a single string, case-independent
|
static Pattern |
maybe(Matchable pat)
Create a pattern that matches a given pattern or the empty string
|
static Pattern |
maybe(java.lang.String str)
Create a pattern that a particular string, or the empty string, case dependent
|
static Pattern |
maybeI(java.lang.String str)
Create a pattern that a particular string, or the empty string, case independent
|
static Pattern |
maybeRepeat(Matchable pat)
Create a pattern that matches zero or more occurrences of a given pattern
|
static Pattern |
maybeRepeat(java.lang.String str)
Create a pattern that matches zero or more occurrences of a particular string, case dependent
|
static Pattern |
maybeRepeatI(java.lang.String str)
Create a pattern that matches zero or more occurrences of a particular string, case dependent
|
static Pattern |
regex(java.lang.String regex)
Parse the given regular expression into a pattern.
|
static Pattern |
regexI(java.lang.String regex)
Parse the given regular expression into a pattern, case independent
|
static Pattern |
repeat(Matchable pat)
Create a pattern that matches one or more occurrences of a given pattern
|
static Pattern |
repeat(java.lang.String str)
Create a pattern that matches one or more occurrences of a particular string, case dependent
|
static Pattern |
repeatI(java.lang.String str)
Create a pattern that matches one or more occurrences of a particular string, case independent
|
Pattern |
then(Matchable tocat)
Create a pattern that matches strings from this pattern, followed by strings from the given pattern
|
Pattern |
then(java.lang.String str)
Create a pattern that matches strings from this pattern, followed by a given string, case dependent
|
Pattern |
thenI(java.lang.String str)
Create a pattern that matches strings from this pattern, followed by a given string, case independent
|
Pattern |
thenMaybe(Matchable pat)
Create a pattern that matches strings from this pattern, maybe followed by a
match of the given pattern
|
Pattern |
thenMaybe(java.lang.String str)
Create a pattern that matches strings from this pattern, maybe followed by a
match of the given string, case dependent
|
Pattern |
thenMaybeI(java.lang.String str)
Create a pattern that matches strings from this pattern, maybe followed by a
match of the given string, case independent
|
Pattern |
thenMaybeRepeat(Matchable pat)
Create a pattern that matches strings from this pattern, followed by zero
or more occurrences of a given pattern
|
Pattern |
thenMaybeRepeat(java.lang.String str)
Create a pattern that matches strings from this pattern, followed by zero
or more occurrences of a given string, case dependent
|
Pattern |
thenMaybeRepeatI(java.lang.String str)
Create a pattern that matches strings from this pattern, followed by zero
or more occurrences of a given string, case independent
|
Pattern |
thenRegex(java.lang.String regexStr)
Create a pattern that matches strings from this pattern,
followed by strings that match a regular expression, case dependent
|
Pattern |
thenRegexI(java.lang.String regexStr)
Create a pattern that matches strings from this pattern,
followed by strings that match a regular expression, case independent
|
Pattern |
thenRepeat(Matchable pat)
Create a pattern that matches strings from this pattern, followed by one
or more occurrences of a given pattern
|
Pattern |
thenRepeat(java.lang.String str)
Create a pattern that matches strings from this pattern, followed by one
or more occurrences of a given string, case dependent
|
Pattern |
thenRepeatI(java.lang.String str)
Create a pattern that matches strings from this pattern, followed by one
or more occurrences of a given string, case independent
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addToNFA, isUnbounded, matchesEmpty, matchesNonEmpty, matchesSomething
public static final Pattern EMPTY
public static final Pattern ALL_STRINGS
public static final Pattern DIGITS
public static final Pattern HEXDIGITS
public static final Pattern INTEGER
public static final Pattern SIMPLE_DECIMAL
INTEGER
, optionally followed by a '.' and zero or more digitspublic static final Pattern FLOAT_DECIMAL
INTEGER
.
It CAN start with a decimal pointpublic static final Pattern DECIMAL
FLOAT_DECIMAL
or an INTEGER
.
Anything this matches is valid for Double.parseDouble(String)
, if the value fitspublic static final Pattern BLOCK_COMMENT
public static final Pattern LINE_COMMENT
public static final Pattern DQ_STRING
public static final Pattern SQ_STRING
public static final Pattern STRING
public static Pattern match(java.lang.String tomatch)
tomatch
- string to matchpublic static Pattern matchI(java.lang.String tomatch)
tomatch
- string to matchpublic static Pattern match(Matchable tomatch)
tomatch
- pattern to matchMatchable
public static Pattern regex(java.lang.String regex)
Syntax supported includes:
regex
- regular expression string to parsepublic static Pattern regexI(java.lang.String regex)
See regex(String)
for syntax information
regex
- regular expression string to parsepublic static Pattern repeat(Matchable pat)
pat
- given patternpublic static Pattern repeat(java.lang.String str)
str
- the string to matchpublic static Pattern repeatI(java.lang.String str)
str
- the string to matchpublic static Pattern maybe(Matchable pat)
pat
- given patternpublic static Pattern maybe(java.lang.String str)
str
- the string to matchpublic static Pattern maybeI(java.lang.String str)
str
- the string to matchpublic static Pattern maybeRepeat(Matchable pat)
pat
- given patternpublic static Pattern maybeRepeat(java.lang.String str)
str
- the string to matchpublic static Pattern maybeRepeatI(java.lang.String str)
str
- the string to matchpublic static Pattern anyOf(Matchable... patterns)
patterns
- patterns to acceptpublic static Pattern anyOf(java.util.Collection<? extends Matchable> patterns)
patterns
- patterns to acceptpublic static Pattern anyOf(java.lang.String p0, java.lang.String p1, java.lang.String... strings)
p0
- first possible stringp1
- second possible stringstrings
- remaining possible strings, if anypublic static Pattern anyOfI(java.lang.String p0, java.lang.String p1, java.lang.String... strings)
p0
- first possible stringp1
- second possible stringstrings
- remaining possible strings, if anypublic static Pattern anyCharIn(java.lang.String chars)
chars
- the characters to acceptpublic Pattern then(Matchable tocat)
tocat
- pattern to append to this onepublic Pattern then(java.lang.String str)
str
- string to append to this patternpublic Pattern thenI(java.lang.String str)
str
- string to append to this patternpublic Pattern thenRegex(java.lang.String regexStr)
regexStr
- regular expression to append to this patternpublic Pattern thenRegexI(java.lang.String regexStr)
regexStr
- regular expression to append to this patternpublic Pattern thenRepeat(Matchable pat)
pat
- the given patternpublic Pattern thenRepeat(java.lang.String str)
str
- the given given stringpublic Pattern thenRepeatI(java.lang.String str)
str
- the given given stringpublic Pattern thenMaybe(Matchable pat)
pat
- the given patternpublic Pattern thenMaybe(java.lang.String str)
str
- the given stringpublic Pattern thenMaybeI(java.lang.String str)
str
- the given stringpublic Pattern thenMaybeRepeat(Matchable pat)
pat
- the given patternpublic Pattern thenMaybeRepeat(java.lang.String str)
str
- the given given stringpublic Pattern thenMaybeRepeatI(java.lang.String str)
str
- the given given stringpublic final Matchable getReversed()
Matchable
The reverse of a pattern matches the reverse of all the strings that this pattern matches
getReversed
in interface Matchable