Class TPattern
java.lang.Object
org.teavm.classlib.java.util.regex.TPattern
- All Implemented Interfaces:
Serializable
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
This constant specifies that a character in aPattern
and a character in the input string only match if they are canonically equivalent.static final int
This constant specifies that aPattern
is matched case-insensitively.static final int
This constant specifies that aPattern
may contain whitespace or comments.static final int
This constant specifies that the '.' meta character matches arbitrary characters, including line endings, which is normally not the case.static final int
This constant specifies that the wholePattern
is to be taken literally, that is, all meta characters lose their meanings.static final int
This constant specifies that the meta characters '^' and '$' match only the beginning and end end of an input line, respectively.static final int
This constant specifies that aPattern
is matched case-insensitively with regard to all Unicode characters.static final int
This constant specifies that a pattern matches Unix line endings ('\n') only against the '.', '^', and '$' meta characters. -
Method Summary
Modifier and TypeMethodDescriptionstatic TPattern
Compiles a regular expression, creating a new Pattern instance in the process.static TPattern
Compiles a regular expression, creating a newPattern
instance in the process.int
flags()
Returns the flags that have been set for thisPattern
.matcher
(CharSequence input) Returns aTMatcher
for thePattern
and a given input.static boolean
matches
(String regex, CharSequence input) Tries to match a given regular expression against a given input.pattern()
Returns the regular expression that was compiled into thisPattern
.static String
Quotes a given string using "\Q" and "\E", so that all other meta-characters lose their special meaning.String[]
split
(CharSequence input) Splits a given input around occurrences of a regular expression.String[]
split
(CharSequence inputSeq, int limit) Splits the given input sequence around occurrences of thePattern
.toString()
-
Field Details
-
UNIX_LINES
public static final int UNIX_LINESThis constant specifies that a pattern matches Unix line endings ('\n') only against the '.', '^', and '$' meta characters.- See Also:
-
CASE_INSENSITIVE
public static final int CASE_INSENSITIVEThis constant specifies that aPattern
is matched case-insensitively. That is, the patterns "a+" and "A+" would both match the string "aAaAaA".- See Also:
-
COMMENTS
public static final int COMMENTSThis constant specifies that aPattern
may contain whitespace or comments. Otherwise comments and whitespace are taken as literal characters.- See Also:
-
MULTILINE
public static final int MULTILINEThis constant specifies that the meta characters '^' and '$' match only the beginning and end end of an input line, respectively. Normally, they match the beginning and the end of the complete input.- See Also:
-
LITERAL
public static final int LITERALThis constant specifies that the wholePattern
is to be taken literally, that is, all meta characters lose their meanings.- See Also:
-
DOTALL
public static final int DOTALLThis constant specifies that the '.' meta character matches arbitrary characters, including line endings, which is normally not the case.- See Also:
-
UNICODE_CASE
public static final int UNICODE_CASEThis constant specifies that aPattern
is matched case-insensitively with regard to all Unicode characters. It is used in conjunction with theCASE_INSENSITIVE
constant to extend its meaning to all Unicode characters.- See Also:
-
CANON_EQ
public static final int CANON_EQThis constant specifies that a character in aPattern
and a character in the input string only match if they are canonically equivalent.- See Also:
-
-
Method Details
-
matcher
Returns aTMatcher
for thePattern
and a given input. TheMatcher
can be used to match thePattern
against the whole input, find occurrences of thePattern
in the input, or replace parts of the input.- Parameters:
input
- the input to process.- Returns:
- the resulting
Matcher
.
-
split
Splits the given input sequence around occurrences of thePattern
. The function first determines all occurrences of thePattern
inside the input sequence. It then builds an array of the "remaining" strings before, in-between, and after these occurrences. An additional parameter determines the maximal number of entries in the resulting array and the handling of trailing empty strings.- Parameters:
inputSeq
- the input sequence.limit
- Determines the maximal number of entries in the resulting array.- For n > 0, it is guaranteed that the resulting array contains at most n entries.
- For n < 0, the length of the resulting array is exactly
the number of occurrences of the
Pattern
+1. All entries are included. - For n == 0, the length of the resulting array is at most
the number of occurrences of the
Pattern
+1. Empty strings at the end of the array are not included.
- Returns:
- the resulting array.
-
split
Splits a given input around occurrences of a regular expression. This is a convenience method that is equivalent to calling the methodsplit(java.lang.CharSequence, int)
with a limit of 0.- Parameters:
input
- the input sequence.- Returns:
- the resulting array.
-
pattern
Returns the regular expression that was compiled into thisPattern
.- Returns:
- the regular expression.
-
toString
-
flags
public int flags()Returns the flags that have been set for thisPattern
.- Returns:
- the flags that have been set. A combination of the constants defined in this class.
- See Also:
-
compile
Compiles a regular expression, creating a newPattern
instance in the process. Allows to set some flags that modify the behavior of thePattern
.- Parameters:
pattern
- the regular expression.flags
- the flags to set. Basically, any combination of the constants defined in this class is valid.- Returns:
- the new
Pattern
instance. - Throws:
TPatternSyntaxException
- if the regular expression is syntactically incorrect.- See Also:
-
compile
Compiles a regular expression, creating a new Pattern instance in the process. This is actually a convenience method that callscompile(String, int)
with aflags
value of zero.- Parameters:
pattern
- the regular expression.- Returns:
- the new
Pattern
instance. - Throws:
TPatternSyntaxException
- if the regular expression is syntactically incorrect.
-
matches
Tries to match a given regular expression against a given input. This is actually nothing but a convenience method that compiles the regular expression into aPattern
, builds aTMatcher
for it, and then does the match. If the same regular expression is used for multiple operations, it is recommended to compile it into aPattern
explicitly and request a reusableMatcher
.- Parameters:
regex
- the regular expression.input
- the input to process.- Returns:
- true if and only if the
Pattern
matches the input. - See Also:
-
quote
Quotes a given string using "\Q" and "\E", so that all other meta-characters lose their special meaning. If the string is used for aPattern
afterwards, it can only be matched literally.- Parameters:
s
- the string to quote.- Returns:
- the quoted string.
-