...

/

Regular Expressions in JavaScript

Regular Expressions in JavaScript

Writing Regex in JavaScript and introduction to the RegExp class of objects.

We'll cover the following...

We know that literals and positional/frequency quantifiers are used to create more elaborate patterns. In this lesson, we will how to write RegEx in JavaScript.

Syntax in JavaScript

There are two formats when writing a RegEx in JavaScript.

Press + to interact
var regex1 = /[a-b]*/; // Create a regex and assign to regex1
var regex2 = RegExp('[a-b]*'); // Create a regex and assign to regex2
console.log(regex1,regex2); // Print the regex variables

In the first format (line 1), use the / operator to tell JavaScript to create a RegEx. ...