精炼正则表达

前端之家收集整理的这篇文章主要介绍了精炼正则表达前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<!DOCTYPE html>
<html>
<head>
<Meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

	
<script>
    // 正则表达式中的小括号"()"。是代表分组的意思。 如果再其后面出现\1则是代表与第一个小括号中要匹配的内容相同。
	// \1必须与小括号配合使用
	// /i 不区分大小写的匹配
var str = "Is is the cost of of gasoline going up up";
var patt1 = /\b([a-z]+) \1\b/ig;
document.write(str.match(patt1));
document.write("<br>");
</script>

<script>
var str = "aaaaacccccbbbbb";
var patt1 =  /(\w)\1*/g;
document.write(str.match(patt1));
document.write("<br>");
</script>

<script>
var str = "aaaaacccccbbbbb";
var patt1 =  /(\w)*/g;
document.write(str.match(patt1));
document.write("<br>");
</script>

<script>
var str = "aais accc is ccbb isb";
var patt1 = /\bis\b/;
document.write(str.match(patt1));
document.write("<br>");
</script>

<script>
var str = "aais a0737-5686123s ccbb isb";
var patt1 = /^0\d\d\d-\d\d\d\d\d\d\d$/;
document.write(str.match(patt1));
document.write("<br>");
</script>

<script>
var str = "a b c a b c a b c d d d d d d  w e r ";
var patt1 = /\w[\w\s\w\s\w]/;
document.write(str.match(patt1));
document.write("<br>");
</script>

<script>
var str = "a b c a b c a b c d d d d d d  w e r ";
var patt1 = /\w\s\w\s\w/;
document.write(str.match(patt1));
document.write("<br>");
</script>

</body>
</html>

eree

https://www.cnblogs.com/zery/p/3438845.html

猜你在找的正则表达式相关文章