[英]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. 它似乎没有正常工作,虽然它使用PHP工作。
在regex
的末尾添加global
选项 - 请参阅下面的演示:
console.log("AkjkljKK".replace(/(?![AZ])./g, ''));
you can use [^AZ]
to remove everything except capital letters. 您可以使用[^AZ]
删除大写字母以外的所有内容。 Also use g
to replace all occurrences and not just the first one. 还可以使用g
来替换所有出现而不仅仅是第一次出现。
var str = "sOmeVALUE"; console.log(str.replace(/[^AZ]/g, ""));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.