Description:
- regexp.exec(str)
returns null if not match found, otherwise returns an array with:
index (the zero-based index of the match in the string),
input (the original string),
[0] (the portion of the string that was matched last),
[1], [2], ..., [n] (the parenthesized substring matches, if such exist)
- regexp.test(str)
The test() method checks if a pattern exists within a
string, and returns true if so, and false() otherwise.
- str.match(regexp)
- str.replace(regexp, replaceStr)
It supports the /g modifier, like Perl, for multiple replacements.
- str.search(regexp)
- str.split(regexp)
The split() method scans a string (which is actually its object) for delimiters,
and splits the string into a list of substrings, returning the resulting list in the
form of an array. The delimiters are determined by repeated pattern matching,
using the given regular expression. Thus, the delimiters may be of any size and do not
need to be the same string on every match. If the pattern does not match at all, the
method returns the original string as a single substring. If it matches once, you get
two substrings, in the form of a two-element array.
Examples:
- Format validation
(source)
re.exec(string)
- Looking for a match
(source) string.search(re)
- Extracting data
(source) array = re.exec(string)
- Replacing strings
(source) re.test(string), string.replace(re,newstring)
- Text processing
(source)
string.split(re), string.replace(re,newstring)
|