DEV Community

Discussion on: My RegExp nightmare

Collapse
 
ben profile image
Ben Halpern

Not alone. I rarely turn to Regex unless it's the absolute obvious choice or it's the existing pattern in the code I'm modifying (and even then, sometimes there's a reason to remove it).

That being said, regex can be the underlying implementation of friendlier interfaces.

Collapse
 
luqman10 profile image
Abdul Qadir Luqman

What do you use in place of regex?

Collapse
 
nektro profile image
Meghan (she/her)

You can implement a replaceAll function for Strings just using the built-in replace and regex:

String.prototype.replaceAll = function(search, replacement) {
    return this.replace(new RegExp(search, 'g'), replacement);
}