正则写法
[abc]查找方括号之间的任何字符
var str = "Is this all there is?";var patt1 = /[a-h]/g;
console.log(str.match(patt1));
[^abc]查找任何不在方括号之间的字符
var str = "hello china";
var patt1 = /[^china]/g;
console.log(str.match(patt1));
查找任何指定的选项
var str = "hello china!How are you?";
var patt1 = /hello|you/g;
console.log(str.match(patt1));
查找单个字符,除了换行和行结束符
var str = "That's hot!";
var patt1 = /h.t/g;
console.log(str.match(patt1));
\w 查找单词字符(字母、数字、下划线)
var str = "Give 100%";
var patt1 = /\w/g;
console.log(str.match(patt1));
\b匹配单词边界
var str = "Hello china";
var patt1 = /\bchina/g;
console.log(str.match(patt1));
推荐网址(很重要)
http://www.qdfuns.com/tools.php?mod=regex
正则表达式分析工具:
https://regexper.com/#sws