1. 正则可以对字符串的信息进行查找、替换和提取操作。
2. 可以处理正则表达式的方法有 regexp.exec ,regexp.test ,string.match,string.replace,string.search,string.split
3. /^ $/i 一个正则表达式模板
4. 例子:匹配一个URL
var url = "http://www.ora.com:80/goodparts?q#fragment";
var parse_url =/^(?:([A-Za-z]+):)?
(\/{0,3}))
([0-9.\-A-Za-z]+)
(?::(\d+))?
(?:\/([^?#]*))?
(?:\?[^#]*)?
(?:#(.*))?
$/;
var result = parse_url.exec(url);
var names = ['url','scheme','slash','host','port','path','query','hash'];
var blanks =' ';
var i;
for(i=0;i<names.length;i+=1){
document.writlen(names[i]+':'+
blanks.substring(names[i].length)+' '+result[i]
);
}
//这段代码输出结果为:
url: http://www.ora.com:80/goodparts?q#fragment
scheme:http
slash://
host:www.ora.com
port:80
path:goodparts
query:q
hash:fragment
(?:表到式)? 非捕获性匹配
\d 匹配数字 [^\d]不匹配数字
\w 等同于[0-9A-Z_a-z]