RegExp in JS | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

RegExp in JS

someone explain to me what exactly is happening here... I understand what the regexp is finding but.. the part I can't wrap my brain around is the 2 parameters going into the function of the second part of the replace... https://code.sololearn.com/WWfo5Rj26eC3/?ref=app

1st Sep 2017, 9:01 AM
// chris
// chris - avatar
1 Antwort
+ 8
The second argument of the .replace() method is the text to be used for replacing the matching pattern OR a callback function returning the string to be use at each positive match (the regex used in your code example use 'g' flag to search for all match in the string, not the first one only;))... You can get more information about how to use callback function as argument of .replace() method in the related documentation on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter
1st Sep 2017, 10:08 AM
visph
visph - avatar