public class

RegExp

extends JavaScriptObject
java.lang.Object
   ↳ com.google.gwt.core.client.JavaScriptObject
     ↳ com.google.gwt.regexp.shared.RegExp

Class Overview

GWT wrapper for the Javascript RegExp class extended with the Javascript String class's replace and split methods, which can take a RegExp parameter.

Summary

Protected Constructors
RegExp()
Public Methods
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.
final MatchResult exec(String input)
Applies the regular expression to the given string.
final boolean getGlobal()
Returns whether the regular expression captures all occurences of the pattern.
final boolean getIgnoreCase()
Returns whether the regular expression ignores case.
final int getLastIndex()
Returns the zero-based position at which to start the next match.
final boolean getMultiline()
Returns whether '$' and '^' match line returns ('\n' and '\r') in addition to the beginning or end of the string.
final String getSource()
Returns the pattern string of the regular expression.
final String replace(String input, String replacement)
Returns the input string with the part(s) matching the regular expression replaced with the replacement string.
final void setLastIndex(int lastIndex)
Sets the zero-based position at which to start the next match.
final SplitResult split(String input)
Splits the input string around matches of the regular expression.
final SplitResult split(String input, int limit)
Splits the input string around matches of the regular expression.
final boolean test(String input)
Determines if the regular expression matches the given string.
[Expand]
Inherited Methods
From class com.google.gwt.core.client.JavaScriptObject
From class java.lang.Object

Protected Constructors

protected RegExp ()

Public Methods

public static RegExp compile (String pattern)

Creates a regular expression object from a pattern with no flags.

Parameters
pattern the Javascript regular expression pattern to compile
Returns
  • a new regular expression
Throws
RuntimeException if the pattern is invalid

public static RegExp compile (String pattern, String flags)

Creates a regular expression object from a pattern with no flags.

Parameters
pattern the Javascript regular expression pattern to compile
flags the flags string, containing at most one occurence of 'g' (getGlobal()), 'i' (getIgnoreCase() ), or 'm' (getMultiline()).
Returns
  • a new regular expression
Throws
RuntimeException if the pattern or the flags are invalid

public final MatchResult exec (String input)

Applies the regular expression to the given string. This call affects the value returned by getLastIndex() if the global flag is set.

Parameters
input the string to apply the regular expression to
Returns
  • a match result if the string matches, else null

public final boolean getGlobal ()

Returns whether the regular expression captures all occurences of the pattern.

public final boolean getIgnoreCase ()

Returns whether the regular expression ignores case.

public final int getLastIndex ()

Returns the zero-based position at which to start the next match. The return value is not defined if the global flag is not set. After a call to exec(String) or test(String), this method returns the next position following the most recent match.

See Also

public final boolean getMultiline ()

Returns whether '$' and '^' match line returns ('\n' and '\r') in addition to the beginning or end of the string.

public final String getSource ()

Returns the pattern string of the regular expression.

public final String replace (String input, String replacement)

Returns the input string with the part(s) matching the regular expression replaced with the replacement string. If the global flag is set, replaces all matches of the regular expression. Otherwise, replaces the first match of the regular expression. As per Javascript semantics, backslashes in the replacement string get no special treatment, but the replacement string can use the following special patterns:

  • $1, $2, ... $99 - inserts the n'th group matched by the regular expression.
  • $& - inserts the entire string matched by the regular expression.
  • $$ - inserts a $.

Parameters
input the string in which the regular expression is to be searched.
replacement the replacement string.
Returns
  • the input string with the regular expression replaced with the replacement string.
Throws
RuntimeException if replacement is invalid

public final void setLastIndex (int lastIndex)

Sets the zero-based position at which to start the next match.

public final SplitResult split (String input)

Splits the input string around matches of the regular expression. If the regular expression is completely empty, splits the input string into its constituent characters. If the regular expression is not empty but matches an empty string, the results are not well defined.

Parameters
input the string to be split.
Returns
  • the strings split off, any of which may be empty.

public final SplitResult split (String input, int limit)

Splits the input string around matches of the regular expression. If the regular expression is completely empty, splits the input string into its constituent characters. If the regular expression is not empty but matches an empty string, the results are not well defined.

Parameters
input the string to be split.
limit the the maximum number of strings to split off and return, ignoring the rest of the input string. If negative, there is no limit.
Returns
  • the strings split off, any of which may be empty.

public final boolean test (String input)

Determines if the regular expression matches the given string. This call affects the value returned by getLastIndex() if the global flag is not set. Equivalent to: exec(input) != null

Parameters
input the string to apply the regular expression to
Returns
  • whether the regular expression matches the given string.