- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
With JavaScript RegExp how to search a string for text that matches regexp?
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>
- Related Articles
- With JavaScript RegExp search a tab character.
- With JavaScript RegExp search a vertical tab character.
- With JavaScript RegExp search a carriage return character.
- With JavaScript RegExp search a hexadecimal number character.
- With JavaScript RegExp search an octal number character.
- MySQL query for alphabetical search (ABC) with REGEXP?
- How to replace string using JavaScript RegExp?
- How to search specific word in MySQL with RegExp?
- Find word character in a string with JavaScript RegExp?
- Find non-word character in a string with JavaScript RegExp
- How to perform Multiline matching with JavaScript RegExp?
- Find digit with JavaScript RegExp.
- How to perform Case Insensitive matching with JavaScript RegExp?
- How to remove HTML Tags with RegExp in JavaScript?
- Which is the JavaScript RegExp to find any alternative text?

Advertisements