![](/img/trans.png)
[英]How to remove all parenthesis and their contents from a string using a regular expression or pure JavaScript and retain other text format
[英]How to remove all numbers and all text from string by using javascript replace?
熱門通過使用javascript從字符串中刪除所有數字和所有文本replace
javascript嗎?
https://jsfiddle.net/jgcsw41s/
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var str = "123aBcD#$%";
var res = str.replace("1-9,a-z,A-Z", "");
alert(res);
}
</script>
當我測試我的代碼時,它不會被替換。
我怎樣才能做到這一點 ?
您可能要嘗試一下,正則表達式。
str.replace(/[a-zA-Z0-9]/g, '')
或正如Rob提到的(感謝Rob)。
str.replace(/\w/g, '')
也會做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.