JavaScript RegExp toString() Method

JavascriptFront End TechnologyObject Oriented Programming

The RegExp toString() method is used to return the string value of the regular expression.

Following is the code for RegExp toString() method −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
body {
   font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
div {
   font-size: 20px;
   font-weight: 500;
<h1>JavaScript RegExp toString() method</h1>
<div class="sample">The quick brown fox jumps over the lazy dog</div>
<button class="Btn">CLICK HERE</button>
<div class="result"></div>
<h3>Click on the above button to get the string value of regular expression.</h3>
let fillEle = document.querySelector(".sample");
let result = document.querySelector(".result");
let regex = new RegExp("fox",'g');
document.querySelector(".Btn").addEventListener("click", () => {
   result.innerHTML = regex.toString();


On clicking the “CLICK HERE” button −

Published on 06-May-2020 12:40:41