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.
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.
Share Improve this question edited Aug 2, 2017 at 15:51 kukkuz 42.4k6 gold badges64 silver badges102 bronze badges asked Aug 2, 2017 at 15:48 Martijn EbbensMartijn Ebbens 2533 silver badges15 bronze badges 1- 1 Note: PHP and JavaScript have different flavors of regex, both of which are expansions on the formal definition of regex, so it isn't necessarily a safe assumption that one language's regex will transfer to another... not to say that this example isn't an overlap between the two – Patrick Barr Commented Aug 2, 2017 at 15:55
2 Answers
Reset to default 6Add the global
option at the end of the regex
- see demo below:
console.log("AkjkljKK".replace(/(?![A-Z])./g, ''));
you can use [^A-Z]
to remove everything except capital letters. Also use g
to replace all occurrences and not just the first one.
var str = "sOmeVALUE";
console.log(str.replace(/[^A-Z]/g, ""));