
- 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
Explain JavaScript Regular Expression modifiers with examples
The JavaScript regular expression modifiers are optional part of a regular expression and allow us to perform case insensitive and global searchers. The modifiers can also be combined together.
Following are the modifiers −
Modifier | Description |
---|---|
g | It enables global matching and returns all the matched results instead of stopping at first match |
i | It enables case insensitive matching |
m | It enables multiline matching |
Example
Following is the code for strict comparison in JavaScript switch statement −
<!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; } .result { font-size: 20px; font-weight: 500; } </style> </head> <body> <h1>JavaScript Regular expression modifiers</h1> <div class="sample"></div> <div style="color: green;" class="result"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to see the modifiers operate on the above string </h3> <script> let sampleEle=document.querySelector('.sample'); let resEle = document.querySelector('.result'); let str = '
Hello world. This is a beautiful world'; sampleEle.innerHTML =str; document.querySelector(".Btn").addEventListener("click", () => { resEle.innerHTML += '/^Hello/m = ' + str.match(/^Hello/m) + '<br>'; resEle.innerHTML += '/world/g = ' + str.match(/world/g) + '<br>'; resEle.innerHTML += '/WORLD/i = ' + str.match(/WORLD/i) + '<br>'; }); </script> </body> </html>
Output
The above code will produce the following output −
On clicking the ‘CLICK HERE’ button −
- Related Articles
- Regular Expression Modifiers in Python
- Regular Expression in C# with Examples
- Regular Expression in Python with Examples?
- How regular expression modifiers work in Python?
- Regular Expression Examples in Python
- Explain C# Quantifiers in regular expression
- Explain C# Substitution in regular expression
- Explain the concept of Regular expression.
- Find the non-digit character with JavaScript Regular Expression
- Regular Expression Matching in JavaScript
- Explain the Star Height of Regular Expression and Regular Language
- Explain Python regular expression search vs match
- Explain C# Grouping Constructs in regular expression
- Explain Regular Expression "A" Metacharacter in Java
- Explain Regular Expression "w" Metacharacter in Java

Advertisements