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 :: javascript remove first space in string 
Javascript :: how to wait in javascript 
Javascript :: javascript clear classlist 
Javascript :: dont trigger useeffect on start 
Javascript :: javascript add css file 
Javascript :: node js express mongodb find all documents 
Javascript :: convert functoin with call back to promise 
Javascript :: Days remaining using moment 
Javascript :: react media query hook 
Javascript :: nodejs express return image 
Javascript :: javascript returned function and copy to clipboard 
Javascript :: validatorjs get all errors 
Javascript :: ng build staging 
Javascript :: js select disabled 
Javascript :: get only day from date in javascript 
Javascript :: jquery closest 
Javascript :: javascript load multiple images 
Javascript :: write json file nodejs 
Javascript :: type of variable js 
Javascript :: js decrement for loop 
Javascript :: jquery remove disabled property from button 
Javascript :: how to add parameters to url javascript 
Javascript :: nodemon package.json start 
Javascript :: refresh event in javascript 
Javascript :: add leading spaced in string javascript 
Javascript :: s3 list objects in folder node js 
Javascript :: retour à la ligne react native 
Javascript :: react js empty build 
Javascript :: js change button text 
Javascript :: js alphabets array 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =