Top Description Fields Constructors Methods
org.jparsec.pattern

public final Class Patterns

extends Object
Class Inheritance
Imports
org.jparsec.internal.util.Checks, java.util.regex.Matcher

Provides common Pattern implementations.
Author
Ben Yu

Field Summary

Modifier and TypeField and Description
public static final Pattern
ALWAYS

A Pattern that always matches with match length 0.

public static final Pattern
ANY_CHAR

A Pattern that matches any character and only mismatches for an empty string.

public static final Pattern
DEC_INTEGER

A Pattern object that matches a decimal integer, which starts with a non-zero digit and is followed by 0 or more digits.

public static final Pattern
DECIMAL

A Pattern object that matches a decimal number that could start with a decimal point or a digit.

public static final Pattern
EOF

A Pattern object that matches if the input has no character left.

public static final Pattern
ESCAPED

A Pattern object that succeeds with match length 2 if there are at least 2 characters in the input and the first character is '\'.

public static final Pattern
FRACTION

A Pattern object that matches a decimal point and one or more digits after it.

public static final Pattern
HEX_INTEGER

A Pattern object that matches a hex integer, which starts with a 0x or 0X, and is followed by one or more hex digits.

public static final Pattern
INTEGER

A Pattern object that matches an integer.

public static final Pattern
NEVER

A Pattern that always returns Pattern#MISMATCH.

public static final Pattern
OCT_INTEGER

A Pattern object that matches an octal integer that starts with a 0 and is followed by 0 or more [0 - 7] characters.

public static final Pattern
REGEXP_MODIFIERS

A Pattern object that matches regular expression modifiers, which is a list of alpha characters.

public static final Pattern
REGEXP_PATTERN

A Pattern object that matches any regular expression pattern string in the form of /some pattern here/.

public static final Pattern
SCIENTIFIC_NOTATION

A Pattern object that matches a scientific notation, such as 1e12, 1.2E-1, etc.

public static final Pattern
STRICT_DECIMAL

A Pattern object that matches a decimal number that has at least one digit before the decimal point.

public static final Pattern
WORD

A Pattern object that matches a standard english word, which starts with either an underscore or an alpha character, followed by 0 or more alphanumeric characters.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Pattern
among(String chars)

Returns a Pattern object that matches if the current character in the input is equal to any character in chars, in which case 1 is returned as match length.

public static Pattern
and(final Pattern... patterns)

Returns a Pattern that matches if all of patterns matches, in which case, the maximum match length is returned.

public static Pattern
atLeast(final int min, final CharPredicate predicate)

Returns a Pattern object that matches if the input starts with min or more characters and all satisfy predicate.

public static Pattern
atMost(final int max, final CharPredicate predicate)

Returns a Pattern that matches up to max number of characters satisfying predicate.

private static Pattern
private static Pattern
public static Pattern
hasAtLeast(final int n)

Returns a Pattern object that matches if the input has at least n characters left.

public static Pattern
hasExact(final int n)

Returns a Pattern object that matches if the input has exactly n characters left.

public static Pattern
isChar(char c)

Returns a Pattern object that matches if the current character in the input is equal to character c, in which case 1 is returned as match length.

public static Pattern
isChar(final CharPredicate predicate)

Returns a Pattern object that matches if the current character in the input satisfies predicate, in which case 1 is returned as match length.

public static Pattern
lineComment(String begin)

Returns a Pattern object that matches a line comment started by begin and ended by EOF or LF (the line feed character).

public static Pattern
longer(Pattern p1, Pattern p2)

Returns a Pattern that tries both p1 and p2, and picks the one with the longer match length.

public static Pattern
longest(final Pattern... patterns)

Returns a Pattern that tries all of patterns, and picks the one with the longest match length.

public static Pattern
many(int min, CharPredicate predicate)
Deprecated Use atLeast(int, CharPredicate) instead.

Returns a Pattern object that matches if the input starts with min or more characters and all satisfy predicate.

public static Pattern
many(final CharPredicate predicate)

Returns a Pattern that matches 0 or more characters satisfying predicate.

public static Pattern
many1(CharPredicate predicate)

Returns a Pattern that matches 1 or more characters satisfying predicate.

private static int
matchMany(CharPredicate predicate, CharSequence src, int len, int from, int acc)

private static int
matchSome(int max, CharPredicate predicate, CharSequence src, int len, int from, int acc)

private static int

Returns:

the number of characters matched, or Pattern#MISMATCH if an unexpected character is encountered.
matchString
(String
the pattern string.
str
,
CharSequence
the input sequence. Must not be null.
src
,
int
start of index to scan characters from src.
begin
,
int
end of index to scan characters from src.
end
)

Matches (part of) a character sequence against a pattern string.

private static int
matchStringCaseInsensitive(String str, CharSequence src, int begin, int end)

pack-priv static Pattern
public static Pattern

Returns:

a Pattern that matches iff the input does not match nested pattern.
not
(Pattern pattern)

public static Pattern
notString(final String string)

Returns a Pattern object that matches if the input has at least 1 character and doesn't match string.

public static Pattern
notStringCaseInsensitive(final String string)

Returns a Pattern object that matches if the input has at least 1 character and doesn't match string case insensitively.

pack-priv static Pattern
public static Pattern
or(Pattern... patterns)

Returns a Pattern that matches if any of patterns matches, in which case, the first match length is returned.

pack-priv static Pattern
public static Pattern
range(char c1, char c2)

Returns a Pattern object that matches if the current character in the input is between character c1 and c2, in which case 1 is returned as match length.

public static Pattern
regex(final Pattern p)

Adapts a regular expression pattern to a Pattern.

public static Pattern
regex(String s)

Adapts a regular expression pattern string to a Pattern.

public static Pattern
repeat(int n, CharPredicate predicate)

Returns a Pattern object that matches if the input has at least n characters and the first n characters all satisfy predicate.

public static Pattern
sequence(Pattern... patterns)

Returns a Pattern object that matches the input against patterns sequentially.

public static Pattern
shorter(Pattern p1, Pattern p2)

Returns a Pattern that tries both p1 and p2, and picks the one with the shorter match length.

public static Pattern
shortest(final Pattern... patterns)

Returns a Pattern that tries all of patterns, and picks the one with the shortest match length.

public static Pattern
some(int min, int max, CharPredicate predicate)
Deprecated Use times(int, int, CharPredicate) instead.

Returns a Pattern that matches at least min and up to max number of characters satisfying predicate,

public static Pattern
some(final int max, final CharPredicate predicate)
Deprecated Use atMost(int, CharPredicate) instead.

Returns a Pattern that matches up to max number of characters satisfying predicate.

public static Pattern
string(final String string)

Returns a Pattern object that matches string literally.

public static Pattern
stringCaseInsensitive(final String string)

Returns a Pattern object that matches string case insensitively.

public static Pattern
times(final int min, final int max, final CharPredicate predicate)

Returns a Pattern that matches at least min and up to max number of characters satisfying predicate,

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALWAYSback to summary
public static final Pattern ALWAYS

A Pattern that always matches with match length 0.

ANY_CHARback to summary
public static final Pattern ANY_CHAR

A Pattern that matches any character and only mismatches for an empty string.

DEC_INTEGERback to summary
public static final Pattern DEC_INTEGER

A Pattern object that matches a decimal integer, which starts with a non-zero digit and is followed by 0 or more digits.

DECIMALback to summary
public static final Pattern DECIMAL

A Pattern object that matches a decimal number that could start with a decimal point or a digit.

EOFback to summary
public static final Pattern EOF

A Pattern object that matches if the input has no character left. Match length is 0 if succeed.

ESCAPEDback to summary
public static final Pattern ESCAPED

A Pattern object that succeeds with match length 2 if there are at least 2 characters in the input and the first character is '\'. Mismatch otherwise.

FRACTIONback to summary
public static final Pattern FRACTION

A Pattern object that matches a decimal point and one or more digits after it.

HEX_INTEGERback to summary
public static final Pattern HEX_INTEGER

A Pattern object that matches a hex integer, which starts with a 0x or 0X, and is followed by one or more hex digits.

INTEGERback to summary
public static final Pattern INTEGER

A Pattern object that matches an integer.

NEVERback to summary
public static final Pattern NEVER

A Pattern that always returns Pattern#MISMATCH.

OCT_INTEGERback to summary
public static final Pattern OCT_INTEGER

A Pattern object that matches an octal integer that starts with a 0 and is followed by 0 or more [0 - 7] characters.

REGEXP_MODIFIERSback to summary
public static final Pattern REGEXP_MODIFIERS

A Pattern object that matches regular expression modifiers, which is a list of alpha characters.

REGEXP_PATTERNback to summary
public static final Pattern REGEXP_PATTERN

A Pattern object that matches any regular expression pattern string in the form of /some pattern here/. '\' is used as escape character.

SCIENTIFIC_NOTATIONback to summary
public static final Pattern SCIENTIFIC_NOTATION

A Pattern object that matches a scientific notation, such as 1e12, 1.2E-1, etc.

STRICT_DECIMALback to summary
public static final Pattern STRICT_DECIMAL

A Pattern object that matches a decimal number that has at least one digit before the decimal point. The decimal point and the numbers to the right are optional.

0, 11., 2.3 are all good candidates. While .1, . are not.

WORDback to summary
public static final Pattern WORD

A Pattern object that matches a standard english word, which starts with either an underscore or an alpha character, followed by 0 or more alphanumeric characters.

Constructor Detail

Patternsback to summary
private Patterns()

Method Detail

amongback to summary
public static Pattern among(String chars)

Returns a Pattern object that matches if the current character in the input is equal to any character in chars, in which case 1 is returned as match length.

andback to summary
public static Pattern and(final Pattern... patterns)

Returns a Pattern that matches if all of patterns matches, in which case, the maximum match length is returned. Mismatch if any one mismatches.

atLeastback to summary
public static Pattern atLeast(final int min, final CharPredicate predicate)

Returns a Pattern object that matches if the input starts with min or more characters and all satisfy predicate.

Since
2.2
atMostback to summary
public static Pattern atMost(final int max, final CharPredicate predicate)

Returns a Pattern that matches up to max number of characters satisfying predicate.

Since
2.2
getModifiersPatternback to summary
private static Pattern getModifiersPattern()
getRegularExpressionPatternback to summary
private static Pattern getRegularExpressionPattern()
hasAtLeastback to summary
public static Pattern hasAtLeast(final int n)

Returns a Pattern object that matches if the input has at least n characters left. Match length is n if succeed.

hasExactback to summary
public static Pattern hasExact(final int n)

Returns a Pattern object that matches if the input has exactly n characters left. Match length is n if succeed.

isCharback to summary
public static Pattern isChar(char c)

Returns a Pattern object that matches if the current character in the input is equal to character c, in which case 1 is returned as match length. Mismatches otherwise.

isCharback to summary
public static Pattern isChar(final CharPredicate predicate)

Returns a Pattern object that matches if the current character in the input satisfies predicate, in which case 1 is returned as match length.

lineCommentback to summary
public static Pattern lineComment(String begin)

Returns a Pattern object that matches a line comment started by begin and ended by EOF or LF (the line feed character).

longerback to summary
public static Pattern longer(Pattern p1, Pattern p2)

Returns a Pattern that tries both p1 and p2, and picks the one with the longer match length. If both have the same length, p1 is favored.

longestback to summary
public static Pattern longest(final Pattern... patterns)

Returns a Pattern that tries all of patterns, and picks the one with the longest match length. If two patterns have the same length, the first one is favored.

manyback to summary
public static Pattern many(int min, CharPredicate predicate)

Deprecated

Use atLeast(int, CharPredicate) instead.

Returns a Pattern object that matches if the input starts with min or more characters and all satisfy predicate.

Annotations
@Deprecated
manyback to summary
public static Pattern many(final CharPredicate predicate)

Returns a Pattern that matches 0 or more characters satisfying predicate.

many1back to summary
public static Pattern many1(CharPredicate predicate)

Returns a Pattern that matches 1 or more characters satisfying predicate.

matchManyback to summary
private static int matchMany(CharPredicate predicate, CharSequence src, int len, int from, int acc)
matchSomeback to summary
private static int matchSome(int max, CharPredicate predicate, CharSequence src, int len, int from, int acc)
matchStringback to summary
private static int matchString(String str, CharSequence src, int begin, int end)

Matches (part of) a character sequence against a pattern string.

Parameters
str:String

the pattern string.

src:CharSequence

the input sequence. Must not be null.

begin:int

start of index to scan characters from src.

end:int

end of index to scan characters from src.

Returns:int

the number of characters matched, or Pattern#MISMATCH if an unexpected character is encountered.

matchStringCaseInsensitiveback to summary
private static int matchStringCaseInsensitive(String str, CharSequence src, int begin, int end)
nextWithEmptyback to summary
pack-priv static Pattern nextWithEmpty(Pattern left, Pattern right)
notback to summary
public static Pattern not(Pattern pattern)
Returns:Pattern

a Pattern that matches iff the input does not match nested pattern.

notStringback to summary
public static Pattern notString(final String string)

Returns a Pattern object that matches if the input has at least 1 character and doesn't match string. 1 is returned as match length if succeeds.

notStringCaseInsensitiveback to summary
public static Pattern notStringCaseInsensitive(final String string)

Returns a Pattern object that matches if the input has at least 1 character and doesn't match string case insensitively. 1 is returned as match length if succeeds.

optionalback to summary
pack-priv static Pattern optional(Pattern pp)
orback to summary
public static Pattern or(Pattern... patterns)

Returns a Pattern that matches if any of patterns matches, in which case, the first match length is returned. Mismatch if any one mismatches.

orWithoutEmptyback to summary
pack-priv static Pattern orWithoutEmpty(Pattern left, Pattern right)
rangeback to summary
public static Pattern range(char c1, char c2)

Returns a Pattern object that matches if the current character in the input is between character c1 and c2, in which case 1 is returned as match length.

regexback to summary
public static Pattern regex(final Pattern p)

Adapts a regular expression pattern to a Pattern.

Warning

in addition to regular expression cost, the returned Pattern object needs to make a substring copy every time it's evaluated. This can incur excessive copying and memory overhead when parsing large strings. Consider implementing Pattern manually for large input.

regexback to summary
public static Pattern regex(String s)

Adapts a regular expression pattern string to a Pattern.

Warning

in addition to regular expression cost, the returned Pattern object needs to make a substring copy every time it's evaluated. This can incur excessive copying and memory overhead when parsing large strings. Consider implementing Pattern manually for large input.

repeatback to summary
public static Pattern repeat(int n, CharPredicate predicate)

Returns a Pattern object that matches if the input has at least n characters and the first n characters all satisfy predicate.

sequenceback to summary
public static Pattern sequence(Pattern... patterns)

Returns a Pattern object that matches the input against patterns sequentially. Te total match length is returned if all succeed.

shorterback to summary
public static Pattern shorter(Pattern p1, Pattern p2)

Returns a Pattern that tries both p1 and p2, and picks the one with the shorter match length. If both have the same length, p1 is favored.

shortestback to summary
public static Pattern shortest(final Pattern... patterns)

Returns a Pattern that tries all of patterns, and picks the one with the shortest match length. If two patterns have the same length, the first one is favored.

someback to summary
public static Pattern some(int min, int max, CharPredicate predicate)

Deprecated

Use times(int, int, CharPredicate) instead.

Returns a Pattern that matches at least min and up to max number of characters satisfying predicate,

Annotations
@Deprecated
someback to summary
public static Pattern some(final int max, final CharPredicate predicate)

Deprecated

Use atMost(int, CharPredicate) instead.

Returns a Pattern that matches up to max number of characters satisfying predicate.

Annotations
@Deprecated
stringback to summary
public static Pattern string(final String string)

Returns a Pattern object that matches string literally.

stringCaseInsensitiveback to summary
public static Pattern stringCaseInsensitive(final String string)

Returns a Pattern object that matches string case insensitively.

timesback to summary
public static Pattern times(final int min, final int max, final CharPredicate predicate)

Returns a Pattern that matches at least min and up to max number of characters satisfying predicate,

Since
2.2