Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript regex replace all

const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';

console.log(p.replaceAll('dog', 'monkey'));
// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"


// global flag required when calling replaceAll with regex
const regex = /Dog/ig;
console.log(p.replaceAll(regex, 'ferret'));

// expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"
Comment

replace all with regex

const regex = new RegExp(oldString, 'g');
const replacedWord = stringToBeChanged.replace(regex, newString);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript unique array of objects by property 
Javascript :: javascript length of number 
Javascript :: adminlte 3 toasts 
Javascript :: pass array of strings to match in str.replace 
Javascript :: js sentence to array 
Javascript :: ReferenceError: window is not defined 
Javascript :: jquery append after 
Javascript :: javascript loop through object array 
Javascript :: save list of dictionaries to json python 
Javascript :: check length of number javascript 
Javascript :: corresponding text to key code js 
Javascript :: shadowoffset react native constructor 
Javascript :: cube camera three js 
Javascript :: find min and max date in array javascript 
Javascript :: adonis lucid join 
Javascript :: js iterate set 
Javascript :: longest substring without repeating characters in javascript 
Javascript :: hide apexcharts tools 
Javascript :: javscript generate empty 2d array 
Javascript :: get last item in map javascript 
Javascript :: lottie delay between loops 
Javascript :: js append class 
Javascript :: select 2nd td jquery 
Javascript :: How to know react and react-native version 
Javascript :: express get url parameters 
Javascript :: get attribute href 
Javascript :: vuejs send required props to dynamic component 
Javascript :: javascript redirect browser 
Javascript :: math format comma separated in javascript 
Javascript :: hover jquery 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =