0% found this document useful (0 votes)
3 views1 page

Regular Expression Basics and Methods

This document provides an overview of how to create and use regular expressions in JavaScript. It explains how to define patterns using slashes or the RegExp object, and how to make expressions case insensitive or global matches using flags like i and g. It also covers matching character classes using brackets, specifying character ranges, escaping special characters, and using the test(), exec(), and match() methods to evaluate patterns.

Uploaded by

khemkaran14
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Regular Expression Basics and Methods

This document provides an overview of how to create and use regular expressions in JavaScript. It explains how to define patterns using slashes or the RegExp object, and how to make expressions case insensitive or global matches using flags like i and g. It also covers matching character classes using brackets, specifying character ranges, escaping special characters, and using the test(), exec(), and match() methods to evaluate patterns.

Uploaded by

khemkaran14
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like