元字符是指擁有特殊含義的字符
- . 表示任意字符
2.轉義字符 \ 如需要使用轉義字符 在構造函數中需要寫 \,字面量中寫一個即可;
3\w 查任意字母數字和下劃線 word
var exp3=/\w/;
alert(exp3.test("!")); //false
alert(exp3.test("abcs1")); //true
4.\W 查找任意非字母數字下劃線
var exp3=/\W/;
alert(exp3.test("!"));//true
alert(exp3.test("ABCSS"));
5.\d 查找任意數字 destiy
var exp3=/\d/;
alert(exp3.test("123")); //true
alert(exp3.test("ABCSSq1")); //true
6 \D 查找非數字,只要含有數字即算
var exp3=/\D/;
alert(exp3.test("123"));//false
alert(exp3.test("ABCSSq1")); //true
7.\s 查找空白字符
var exp3=/\s/;
alert(exp3.test("123 1"));
alert(exp3.test("ABCSSq1"));
7.\S 查找非空白字符
var exp3=/\s/;
alert(exp3.test("123 1"));
alert(exp3.test("ABCSSq1"));
8.\b 匹配單詞邊界
/內容\b/ 表示匹配結尾單詞邊界
var exp3=/t\b/;
console.log(exp3.test("height"));
console.log(exp3.test("abs"));
/\b內容/ 表示匹配開頭單詞邊界
var exp2=/\bh/;
console.log(exp2.test("height"));
console.log(exp2.test("abs"));
9.\B 匹配非單詞邊界
\B 元字符通常用于查找不處在單詞的開頭或結尾的匹配。
var exp3=/t\B/;
console.log(exp3.test("height"));
console.log(exp3.test("abs"));
/\B 內容/ 表示匹配開頭非單詞邊界
var exp2=/\Bgh/;
console.log(exp2.test("height"));
console.log(exp2.test("aght"));