Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js regex i modifier

// The RegExp i Modifier in JavaScript is used to perform case-insensitive matching in the string.

/regexp/i 
// OR
new RegExp("regexp", "i")

// example
const regex = /dannyglade/gi // /gi is modifiers
const str1 = 'DannyGlade' // will match
const str2 = 'dannyglade' // will also match
const str3 = 'DaNNyGlaDe' // will also match

const match = regex.test(str1) 
const match = str2.match(regex) // alternate way to test regex
Comment

javascript Regular Expression Modifier

const string = 'Hello hello hello';

// performing a replacement
const result1 = string.replace(/hello/, 'world');
console.log(result1); // Hello world hello

// performing global replacement
const result2 = string.replace(/hello/g, 'world');
console.log(result2); // Hello world world

// performing case-insensitive replacement
const result3 = string.replace(/hello/i, 'world');
console.log(result3); // world hello hello

// performing global case-insensitive replacement
const result4 = string.replace(/hello/gi, 'world');
console.log(result4); // world world world
Comment

PREVIOUS NEXT
Code Example
Javascript :: post css nesting nuxt 
Javascript :: javascript statements 
Javascript :: javascript best practices 
Javascript :: ajax introduction 
Javascript :: mui on node 
Javascript :: httpclient post raw json body 
Javascript :: salesforce set hours javascript 
Javascript :: nodejs: Basic: managing file: Read, Write, Create, Delete 
Javascript :: convert string to slug javascript 
Javascript :: cannot set headers after they are sent to the client mongoose 
Javascript :: symbol in keyword for arrow below 
Javascript :: flip image on y axis phaser 
Javascript :: link change page react 
Javascript :: phaser add animation event 
Javascript :: phaser remove animation event 
Javascript :: NodeJS/express : Cached and 304 status code on chrome 
Javascript :: scan token deploy js 
Javascript :: using lambda for elasticache node.js 
Javascript :: debounce getx 
Javascript :: Assign A New Method To Every Node 
Javascript :: compare text 
Javascript :: forms in angular 
Javascript :: sort array method 
Javascript :: create a class variable js 
Javascript :: javascript practice questions 
Javascript :: react native 
Javascript :: uncaught typeerror e.indexof is not a function jquery load 
Javascript :: react-hook-form-input npm 
Javascript :: javascript pass array by value 
Javascript :: javascript after 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =