Example: Simple regular expressions
Here are reminders of the meanings of the modifier and the methods:
Modifier | Meaning |
---|---|
i |
(case-insensitive) |
g |
(global, find all matches) |
m |
(multiline matching) |
The string method .search(exp)
consumes a regular expression and produces the position of the first match, and the string .replace(exp, replace)
consumes a regular expression and replacement string and produces the string formed by replacing each pattern by the replacement string.
Try modifiying the script to try some other patterns.
Note:
Hints:
- undefined
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
var example = "A and a and The the tHe the";
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX