Regular Expression Tutorial
Ways to create a Regular Expression
1. Var pattern = /pattern/;
2. Var pattern = new RegExp(pattern);
Use i to make the expression case insensitive as /pattern/i
Use g to make an expression match if other characters are also present in the
matching pattern.
As /pattern/g
Match of a class of Characters
Wrap the patterns inside brackets [] to make the matching string compare the
complete class of characters available inside bracket.
Var pattern = /[abc]/;
[Link]([Link](a));
To test a pattern use test method of RegExp.
[Link](a);
Provide the range for matching in the brackets as [0-7]
Use \ to escape special characters as $, . or [, use backslash before the special
character
Using the test() method one can find if there is any match or not. But if someone
want to get the occurrences of the first match one should use exec() method.
Another method is available is match() method, the difference between the exec
and match method is the match method returns all the occurrences of the match