Help with regex | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

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

19th May 2019, 8:03 PM
Witty Phantom
Witty Phantom - avatar
6 Answers
+ 3
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);
19th May 2019, 10:00 PM
Diego
Diego - avatar
+ 2
What have you done so far?
19th May 2019, 9:06 PM
Diego
Diego - avatar
+ 1
Hi Diego, I've successfully captured the first 3 words, but can't capture anything after that. /^((?:\S+\s+){2}\S+).* ([a-z]+)/
19th May 2019, 9:13 PM
Witty Phantom
Witty Phantom - avatar
+ 1
What programming language are you using?
19th May 2019, 9:20 PM
Diego
Diego - avatar
+ 1
AWESOME! This works great! Thanks Diego.
19th May 2019, 10:12 PM
Witty Phantom
Witty Phantom - avatar
0
I mainly use JavaScript, but doesn't regex have the same syntax in all languages?
19th May 2019, 9:21 PM
Witty Phantom
Witty Phantom - avatar