diff --git "a/36\351\273\204\345\257\214\350\264\265/11-16\344\275\234\344\270\232/11-16-\346\255\243\345\210\231&\345\274\202\345\270\270\347\254\224\350\256\260.md" "b/36\351\273\204\345\257\214\350\264\265/11-16\344\275\234\344\270\232/11-16-\346\255\243\345\210\231&\345\274\202\345\270\270\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..c1d762b77ebf5b48ad6cf92263893c31fb5974b0 --- /dev/null +++ "b/36\351\273\204\345\257\214\350\264\265/11-16\344\275\234\344\270\232/11-16-\346\255\243\345\210\231&\345\274\202\345\270\270\347\254\224\350\256\260.md" @@ -0,0 +1,127 @@ +第十七课正则&异常笔记: + +# 正则 + +1.使用replace捕获分组 + +2.引用:\1:引用子表达式内容 + +例: + +``` +console.log(/(aab)\1{4}/.exec('aabaabaabaabaab')); +``` + +反捕获:?::将捕获到的子表达式隐藏 + +例: + +``` +console.log(/(?:aabc)(ccab)/.exec('aabcccabaabcccab')); +``` + +|(or) + +文件名由字母、数字、下划线构成,不可以以数字开头,后缀为.zip/rar/gz + +``` +console.log(/[^\d]*\.zip|rar|gz/.exec('zip.zip')); +``` + +例题: + +``` + 0 - 99 9 + 0-9 10-99 + \d|[1-9][\d] + 自左向右匹配,一旦匹配上 就不再回头 + console.log(/[1-9][\d]|\d/.exec('9')); +``` + +环视 + +?=:紧跟着 ?!:不紧跟着 ?:-->反捕获 ??--> 非贪婪{0,1} + +c紧跟着的b,查的是b + +``` +console.log(/b(?=c)/.exec('abcbd')); +``` + +b紧跟着的a,查的是a + +``` +console.log(/a(?!b)/.exec('abca')); +``` + +# 异常 + +异常处理 + +try:尝试捕获异常,里面放的可能是出错的代码 + +基本格式: + +``` +try{ + +}catch(error){ + +} +``` + +报错后的代码终止执行例题: + +``` +try { + console.log('1'); + throw new Error('error 1');//错误 + console.log('2 '); + } catch (error) { + console.log('3'); + } finally { + console.log('4'); + } + console.log('5'); + //1 345 +``` + +每次只能捕获一个异常例题: + +``` +try { + console.log('1'); + throw new Error('error 1'); //error + console.log('2 '); + } catch (error) { + console.log('3'); + } finally { + console.log('4'); + try { + throw new Error('error 2'); //error + } catch (error) { + + } + console.log('5'); + } + console.log('6'); + + function fn1() { + var a = 6; + try { + console.log('1'); + return a; //6 + } catch (error) { + console.log(error.message); + } finally { + console.log('2'); + a = 9; + // return a; + } + + + } + const fn1Result = fn1(); + console.log('fn1Result:' + fn1Result); +``` + diff --git "a/36\351\273\204\345\257\214\350\264\265/11-16\344\275\234\344\270\232/11-16-\346\255\243\345\210\231\344\275\234\344\270\232.html" "b/36\351\273\204\345\257\214\350\264\265/11-16\344\275\234\344\270\232/11-16-\346\255\243\345\210\231\344\275\234\344\270\232.html" new file mode 100644 index 0000000000000000000000000000000000000000..d5b83efc25e06bd6aef816addaba99f7e3617d38 --- /dev/null +++ "b/36\351\273\204\345\257\214\350\264\265/11-16\344\275\234\344\270\232/11-16-\346\255\243\345\210\231\344\275\234\344\270\232.html" @@ -0,0 +1,26 @@ + + +
+ + + +