public class RegExp
extends java.lang.Object
There are a few small incompatibilities between the two implementations. Java-specific constructs in the regular expression syntax (e.g. [a-z&&[^bc]], (?<=foo), \A, \Q) work only in the pure Java implementation, not the GWT implementation, and are not rejected by either. Also, the Javascript-specific constructs $` and $' in the replacement expression work only in the GWT implementation, not the pure Java implementation, which rejects them.
Modifier and Type | Method and Description |
---|---|
static RegExp |
compile(java.lang.String pattern)
Creates a regular expression object from a pattern with no flags.
|
static RegExp |
compile(java.lang.String pattern,
java.lang.String flags)
Creates a regular expression object from a pattern using the given flags.
|
MatchResult |
exec(java.lang.String input)
Applies the regular expression to the given string.
|
boolean |
getGlobal()
Returns whether the regular expression captures all occurrences of the
pattern.
|
boolean |
getIgnoreCase()
Returns whether the regular expression ignores case.
|
int |
getLastIndex()
Returns the zero-based position at which to start the next match.
|
boolean |
getMultiline()
Returns whether '$' and '^' match line returns ('\n' and '\r') in addition
to the beginning or end of the string.
|
java.lang.String |
getSource()
Returns the pattern string of the regular expression.
|
static java.lang.String |
quote(java.lang.String input)
Returns a literal pattern
String for the specified
String . |
java.lang.String |
replace(java.lang.String input,
java.lang.String replacement)
Returns the input string with the part(s) matching the regular expression
replaced with the replacement string.
|
void |
setLastIndex(int lastIndex)
Sets the zero-based position at which to start the next match.
|
SplitResult |
split(java.lang.String input)
Splits the input string around matches of the regular expression.
|
SplitResult |
split(java.lang.String input,
int limit)
Splits the input string around matches of the regular expression.
|
boolean |
test(java.lang.String input)
Determines if the regular expression matches the given string.
|
public static RegExp compile(java.lang.String pattern)
pattern
- the Javascript regular expression pattern to compilejava.lang.RuntimeException
- if the pattern is invalidpublic static RegExp compile(java.lang.String pattern, java.lang.String flags)
pattern
- the Javascript regular expression pattern to compileflags
- the flags string, containing at most one occurrence of 'g'
(getGlobal()
), 'i'
(getIgnoreCase()
),
or 'm'
(getMultiline()
).java.lang.RuntimeException
- if the pattern or the flags are invalidpublic static java.lang.String quote(java.lang.String input)
String
for the specified
String
.
This method produces a String
that can be used to
create a RegExp
that would match the string
s
as if it were a literal pattern.
input
- The string to be literalizedpublic MatchResult exec(java.lang.String input)
getLastIndex()
if the global flag is set.input
- the string to apply the regular expression tonull
public boolean getGlobal()
public boolean getIgnoreCase()
public int getLastIndex()
exec(String)
or test(String)
, this method returns
the next position following the most recent match.getGlobal()
public boolean getMultiline()
public java.lang.String getSource()
public java.lang.String replace(java.lang.String input, java.lang.String replacement)
input
- the string in which the regular expression is to be searched.replacement
- the replacement string.java.lang.RuntimeException
- if replacement
is invalidpublic void setLastIndex(int lastIndex)
public SplitResult split(java.lang.String input)
input
- the string to be split.public SplitResult split(java.lang.String input, int limit)
input
- the string to be split.limit
- the maximum number of strings to split off and return,
ignoring the rest of the input string. If negative, there is no
limit.public boolean test(java.lang.String input)
getLastIndex()
if the global flag is
set. Equivalent to: exec(input) != null
input
- the string to apply the regular expression to