
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Search String for Text Matching RegExp in JavaScript
To search a string for a text that matches RegExp, use rhe exec() method in JavaScript. If it finds a match, it returns an array of results; otherwise, it returns null.
The following is the parameter −
- string − The string to be searched
Example
You can try to run the following code to search a string for text matching RegExp −
<html> <head> <title>JavaScript RegExp exec Method</title> </head> <body> <script> var str = "JavaScript is an interesting scripting language"; var re = new RegExp( "script", "g" ); var result = re.exec(str); document.write("Test 1 - returned value : " + result); re = new RegExp( "pushing", "g" ); var result = re.exec(str); document.write("<br />Test 2 - returned value : " + result); </script> </body> </html>
Advertisements