Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing everything except capital letters using replace

Yeah, I'm trying to remove everything except the capital letters, though it doesn't really seem to go well.

I used the following code,

String.replace(/(?![A-Z])./, '');

It doesn't seem to work properly, while it does work using PHP.

like image 555
Martijn Ebbens Avatar asked Dec 24 '22 15:12

Martijn Ebbens


1 Answers

Add the global option at the end of the regex - see demo below:

console.log("AkjkljKK".replace(/(?![A-Z])./g, ''));
like image 72
kukkuz Avatar answered Dec 28 '22 11:12

kukkuz