Class Pattern
- java.lang.Object
-
- net.sf.eBus.util.regex.Pattern
-
- All Implemented Interfaces:
Serializable,Comparable<Pattern>
public final class Pattern extends Object implements Comparable<Pattern>, Serializable
A compiled regular expression representation.Patterns are created indirectly by calling
compile(java.lang.String)and passing in the regular expression text. If the regular expression is successfully compiled, then aPatterninstance is returned. Use thematches(java.lang.CharSequence)method to test if a character sequence matches the regular expression.Pattern instance are immutable and safe for concurrent thread usage.
Summary of regular-expression constructs
Construct Matches Characters x The character x \\ The backslash character \0n The character with octal value 0n (0 ≤ n ≤ 7) \0nn The character with octal value 0nn (0 ≤ n ≤ 7) \0mnn The character with octal value 0mnn (0 ≤ m ≤ 3, 0 ≤ n ≤ 7) \xhh The character with hexadecimal value 0xhh \uhhhh The character with hexadecimal value 0xhhhh \t The tab character ('\u0009') \n The newline (line feed) character ('\u000A') \r The carriage-return character ('\u000D') \f The form-feed character ('\u000C') \a The alert (bell) character ('\u0007') \e The escape character ('\u001B') Character classes [abc] a, b, or c (simple class) [^abc] Any character except a, b, or c (negation) [a-zA-Z] a through z or A through Z, inclusive (range) Predefined character classes . Any character. \d A digit: [0-9] \D A non-digit: [^0-9] \s A whitespace character: [ \t\n\0x0B\f\r] \S A non-whitespace character: [^\s] \w A word character: [a-zA-Z_0-9] \W A non-word character: [^\w] Greedy quantifiers X? X, once or not at all. X* X, zero or more times. X+ X, one or more times. X{n} X, exactly n times. X{n,} X, at least n times. X{, n} X, zero to at most n times. X{n, m} X, at least n times but no more than m times where n ≤ m.
This regular expression class is specifically designed to efficiently search
TernarySearchTreekeys. Hence the reason for developing a separate regular expression package fromjava.util.regex. If you need to perform regular expression pattern matching over generic character sequences, then use thejava.util.regex.Patternclass which supports more extensive regular expression constructs.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Pattern pattern)Returns an integer value < zero if this pattern is less than the argument; zero if this pattern is equal to the argument; > zero if this pattern is greater than the argument.static Patterncompile(String regex)Returns the eBus regular expression pattern compiled from the given string.Component[]components()Returns the pattern's components.booleanequals(Object object)Returnstrueif this object and the argumentobjectare both regular expression patterns with the same underlying pattern string andfalseotherwise.inthashCode()Returns a hosh code based on the regular expression pattern string.booleanmatches(CharSequence input)Returnstrueif this regular expression pattern acceptsinputandfalseotherwise.intmaximumSize()Returns a matching string's maximum possible size.intminimumSize()Returns a matching string's minimum possible size.Stringpattern()Returns the original regular expression pattern string.StringtoString()Returns this pattern's textual representation.
-
-
-
Method Detail
-
compareTo
public int compareTo(Pattern pattern)
Returns an integer value < zero if this pattern is less than the argument; zero if this pattern is equal to the argument; > zero if this pattern is greater than the argument.- Specified by:
compareToin interfaceComparable<Pattern>- Parameters:
pattern- Compare agains this pattern- Returns:
- an integer value < zero if this pattern is less than the argument; zero if this pattern is equal to the argument; > zero if this pattern is greater than the argument.
-
pattern
public String pattern()
Returns the original regular expression pattern string.- Returns:
- the original regular expression pattern string.
-
components
public Component[] components()
Returns the pattern's components.- Returns:
- the pattern's components.
-
minimumSize
public int minimumSize()
Returns a matching string's minimum possible size.- Returns:
- a matching string's minimum possible size.
-
maximumSize
public int maximumSize()
Returns a matching string's maximum possible size.-1means there is no limit.- Returns:
- a matching string's maximum possible size.
-
matches
public boolean matches(CharSequence input)
Returnstrueif this regular expression pattern acceptsinputandfalseotherwise.- Parameters:
input- match this character sequence against this regular expression pattern.- Returns:
trueif this regular expression pattern acceptsinputandfalseotherwise.
-
equals
public boolean equals(Object object)
Returnstrueif this object and the argumentobjectare both regular expression patterns with the same underlying pattern string andfalseotherwise.
-
toString
public String toString()
Returns this pattern's textual representation.
-
hashCode
public int hashCode()
Returns a hosh code based on the regular expression pattern string.
-
compile
public static Pattern compile(String regex)
Returns the eBus regular expression pattern compiled from the given string.- Parameters:
regex- compile this string into an eBus pattern.- Returns:
- the eBus regular expression pattern compiled from the given string.
- Throws:
IllegalArgumentException- ifregexisnull.PatternSyntaxException- ifregex's syntax is invalid.
-
-