
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
JavaScript RegExp toString() Method
The RegExp toString() method is used to return the string value of the regular expression.
Following is the code for RegExp toString() method −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } div { font-size: 20px; font-weight: 500; } </style> </head> <body> <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> <script> 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(); }); </script> </body> </html>
Output
On clicking the “CLICK HERE” button −
- Related Articles
- JavaScript RegExp test() Method
- Java toString() method.
- C# Enum ToString() Method
- Java Signature toString() method
- C# Int16.ToString() Method
- What is the role of exec method in JavaScript RegExp?
- ShortBuffer toString() method in Java
- Provider toString() method in Java
- Duration toString() method in Java
- MonthDay toString() Method in Java
- Instant toString() method in Java
- LocalDate toString() method in Java
- LocalDateTime toString() method in Java
- LocalTime toString() method in Java
- Int64.ToString() Method in C#

Advertisements