簡單的Js正則表達式:濾除多余字符
來源:程序員人生 發布時間:2014-03-31 12:17:15 閱讀次數:3061次
簡單的Js正則表達式:濾除多余字符
利用正則表達法除去字符串中的重復字符,一個簡單的JavaScript正則表達式實例,將一串含有重復字符串中的多余字符濾除掉。
代碼如下:
<html>
<head>
<title>利用正則表達法除去字符串中的重復字符</title>
</head>
<body>
<script language="javascript">
str = "Google"
str1 = str.replace(/(.).*1/g,"$1")
document.write(str + "<br>");
document.write(str1);
</script>
</body>
</html>