public class RegExp extends JavaScriptObject
Modifier | Constructor and Description |
---|---|
protected |
RegExp() |
Modifier and Type | Method and Description |
---|---|
static RegExp |
compile(String pattern)
Creates a regular expression object from a pattern with no flags.
|
static RegExp |
compile(String pattern,
String flags)
Creates a regular expression object from a pattern with no flags.
|
MatchResult |
exec(String input)
Applies the regular expression to the given string.
|
boolean |
getGlobal()
Returns whether the regular expression captures all occurences 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.
|
String |
getSource()
Returns the pattern string of the regular expression.
|
static String |
quote(String input)
Returns a literal pattern
String for the specified
String . |
String |
replace(String input,
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(String input)
Splits the input string around matches of the regular expression.
|
SplitResult |
split(String input,
int limit)
Splits the input string around matches of the regular expression.
|
boolean |
test(String input)
Determines if the regular expression matches the given string.
|
cast, createArray, createArray, createFunction, createObject, equals, hashCode, toSource, toString
public static RegExp compile(String pattern)
pattern
- the Javascript regular expression pattern to compileRuntimeException
- if the pattern is invalidpublic static RegExp compile(String pattern, String flags)
pattern
- the Javascript regular expression pattern to compileflags
- the flags string, containing at most one occurence of 'g'
(getGlobal()
), 'i'
(getIgnoreCase()
), or 'm'
(getMultiline()
).RuntimeException
- if the pattern or the flags are invalidpublic static String quote(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 final MatchResult exec(String input)
getLastIndex()
if the global flag is set.input
- the string to apply the regular expression tonull
public final boolean getGlobal()
public final boolean getIgnoreCase()
public final int getLastIndex()
exec(String)
or test(String)
, this method returns
the next position following the most recent match.getGlobal()
public final boolean getMultiline()
public final String getSource()
public final String replace(String input, String replacement)
input
- the string in which the regular expression is to be searched.replacement
- the replacement string.RuntimeException
- if replacement
is invalidpublic final void setLastIndex(int lastIndex)
public final SplitResult split(String input)
input
- the string to be split.public final SplitResult split(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 final boolean test(String input)
getLastIndex()
if the global flag is
not set. Equivalent to: exec(input) != null
input
- the string to apply the regular expression toCopyright © 2018. All rights reserved.