标签:ref 单词 character blank 单个字符 oct png 元字符 www
元字符(Metacharacter)是拥有特殊含义的字符:
元字符 描述
(1) . 查找单个字符,除了换行和行结束符。
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>点</title>
</head>
<body>
<script type="text/javascript">
str=‘index and php 2 and Php and pHp 3 and indox and 20 indax and indBx andpcp and pp and p p and p-p and p\np and p9p‘;
arr = str.match(/p.p/ig)//查找单个字符,除了换行和行结束符。
alert(arr);
</script>
</body>
</html>
效果如图:

(2)\w 查找单词字符。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>反斜线小写w查找单词字符</title>
</head>
<body>
<script type="text/javascript">
str=‘index and php 2 and Php and pHp 3 and indox and 20 indax and indBx andpcp and pp and p p and p-p and p\np and p9p‘;
arr = str.match(/p\wp/ig)//反斜线小写w查找单词字符
alert(arr);
</script>
</body>
</html>
效果图:

(3) \W 查找非单词字符。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>反斜线大写W查找非单词字符</title>
</head>
<body>
<script type="text/javascript">
str=‘index and php 2 and Php and pHp 3 and indox and 20 indax and indBx andpcp and pp and p p and p-p and p\np and p9p‘;
arr = str.match(/p\Wp/ig)//反斜线大写W查找非单词字符
alert(arr);
</script>
</body>
</html>
效果图:

标签:ref 单词 character blank 单个字符 oct png 元字符 www
原文地址:http://www.cnblogs.com/huanghuali/p/7654504.html