JavaScript RegExp exec() Method

You are Here:

JavaScript RegExp exec() Method

The RegExp exec() method executes a regular expression search within a string, and returns the results in an array, or null.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Click me</button> <p id="point"></p> <script> function myFunction(){ var str = "Pot I got is hot"; // Try to change "o" to "z" var pattern = new RegExp("o"); var result = pattern.exec(str); document.getElementById("point").innerHTML = result; } </script> </body> </html>

Syntax

RegExpObject.exec(string)

Parameter Values

ValueTypeExplanation
stringRequiredThe string to be searched.

Return Value

ValueExplanation
arrayReturn an array representing a search character(s) if matched.
nullReturn null if a search character(s) was not matched.

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author