© Jörg Krause 2017

Jörg Krause, Introducing Regular Expressions, 10.1007/978-1-4842-2508-0_3

3. The JavaScript Functions

Jörg Krause

(1)Berlin, Germany

JavaScript provides an object named RegExp. You can create an instance by using new or the literal //.

The RegExp Object

I’ll start with an overview and follow it with several examples.

Methods

Apart from the RegExp object, you can use several built-in string functions in JavaScript to deal with regular expressions. The object knows these methods:

  • exec(): Executes the test and returns the first hit.

  • test(): Executes the test and returns either true or false.

  • toString(): Returns the expression as a string.

The exec method returns an object that has the following content:

  • An array with the groups (counting ...

Get Introducing Regular Expressions: JavaScript and TypeScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.