Help with regex | SoloLearn: Learn to code for FREE!


Help with regex

I'm trying to create a regex that would turn this string: "pain around the eyes, nose, cheeks, or forehead" To this: "pain around the eyes, pain around the nose, pain around the cheeks, pain around the forehead" I've been trying for an hour now but no luck :( Thanks in advance

5/19/2019 8:03:17 PM

Witty Phantom

6 Answers

New Answer


var re = /, (or)?/g; var str = "pain around the eyes, nose, cheeks, or forehead"; var newstr = str.replace(re, ", pain around the "); console.log(newstr);


What have you done so far?


Hi Diego, I've successfully captured the first 3 words, but can't capture anything after that. /^((?:\S+\s+){2}\S+).* ([a-z]+)/


What programming language are you using?


AWESOME! This works great! Thanks Diego.


I mainly use JavaScript, but doesn't regex have the same syntax in all languages?