Java Reference
In-Depth Information
Here, pattern is the pattern to be matched in the input text. It can be another
RegExp object or a string representing the pattern. flags is a string that defines the
text-matching rules. It may be an empty string, undefined , or a string containing one or
all of the characters: g , i , and m . It is a SyntaxError to repeat the flags in a RegExp object.
Table 4-15 contains the list of flags and their descriptions.
Table 4-15. The List of Flags Used in Regular Expressions
Flag
Description
g
Performs a global match. The default is to stop the match after the first match
i
Performs a case-insensitive match. The default is to perform a case-sensitive
match
m
Enables multiline mode. The default is single-line mode. In single-line mode,
the ^ and $ characters in the pattern match the beginning and end of the
input text, respectively. In multiline mode, they match the beginning and end
of the input text as well as the beginning and end of lines
The RegExp object can be used as a function or a constructor with the following
rules:
pattern is a RegExp object and flags is undefined , pattern is
returned
If
pattern is a RegExp object and flags is not undefined , a
SyntaxError is generated
If
RegExp object is returned that represents a pattern
specified by pattern and flags
The following are examples of creating RegExp objects:
Otherwise, a
// Creates a RegExp object with a pattern to match the word
// "Java" in the input text. The g flag will perform the match
// globally and the m flag will use multiline mode.
var pattern1 = new RegExp("Java", "gm");
// Assigns pattern1 to pattern2. The constructor returns
// pattern1 because its first argument, pattern1, is a RegExp object.
var pattern2 = new RegExp(pattern1);
// Prints true
print(pattern1 === pattern2);
 
 
Search WWH ::




Custom Search