<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>正则表达式</title>
</head>
<body>
</body>
<script type="text/javascript">
var c = 'This is齐 123 a 天456long 382大 long 盛long long clause';
// 查找所有的子串 is
console.log(c.search(/\bis\b/)); // \b表示单词的边界
console.log(c.match(/\bis\b/));
// 抽取所有的单词
console.log(c.match(/\b\w+\b/g));
// 每个单词首字母大写
/* i执行大小写不敏感的表达式
g执行全局表达式
m执行多行表达式
*/
console.log(c.replace(/\b\w+\b/g,function(word){
return word[0].toUpperCase() + word.substr(1);
}));
//抽取所有的数字
console.log(c.match(/[0123456789]+/g));
console.log(c.match(/[0-9]+/g));
console.log(c.match(/[0123456789]+/g));
//抽取所有的字母
console.log(c.match(/[A-Za-z]+/g));
//抽取所有的非字母
console.log(c.match(/[^A-Za-z]+/g));
//抽取所有的汉字
console.log(c.match(/[\u4E00-\u9FA5]+/g));
//查找第一个单词
console.log(c.match(/^\w+/g));
//查找最后一个单词
console.log(c.match(/\w+$/g));
</script>
</html>