- 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
How to define a Regular Expression in JavaScript?
A regular expression is an object that describes a pattern of characters.
The JavaScript RegExp class represents regular expressions, and both String and RegExp define methods that use regular expressions to perform powerful pattern-matching and search-and-replace functions on the text. A regular expression could be defined with the RegExp () constructor, as follows −
var pattern = new RegExp(pattern, attributes); or var pattern = /pattern/attributes;
The following are the parameters −
- pattern − A string that specifies the pattern of the regular expression or another regular expression.
- attributes − An optional string containing any of the "g", "i", and "m" attributes that specify global, case-insensitive, and multiline matches, respectively.
- Related Articles
- How to clone a given regular expression in JavaScript?
- How to test and execute a regular expression in JavaScript?
- How to write a Regular Expression in JavaScript to remove spaces?
- How to define a JavaScript function using the expression?
- Regular Expression Matching in JavaScript
- How to put variable in regular expression match with JavaScript?
- How to write JavaScript Regular Expression for multiple matches?
- Regular expression to match numbers only in JavaScript?
- How do you access the matched groups in a JavaScript regular expression?
- How to match a regular expression against a string?
- With JavaScript Regular Expression find a non-whitespace character.
- Explain JavaScript Regular Expression modifiers with examples
- How to validate a URL using regular expression in C#?
- How to match a word in python using Regular Expression?
- How to match a whitespace in python using Regular Expression?

Advertisements