基本概念
( ) | 標記一個子表達式的開始和結束位置。子表達式可以獲取供以後使用。要匹配這些字符,請使用 \( 和 \)。 |
* | 匹配前面的子表達式零次或多次。要匹配 * 字符,請使用 \*。 |
. | 匹配除換行符 \n 之外的任何單字符。要匹配 . ,請使用 \. 。 |
解決方案
var content="鏈接:https://pan.baidu.com/s/14Ohd4jLuMWLRtqIt6eUNKg\n提取碼:5dlw\n複製這段內容後打開百度網盤手機App,操作更方便哦";
var reg = /鏈接:(.*)/;
// https://pan.baidu.com/s/14Ohd4jLuMWLRtqIt6eUNKg
console.log(reg.exec(content)[1].trim());
var reg1 = /提取碼:(.*)/;
// 5dlw
console.log(reg1.exec(content)[1].trim());
參考文章
https://blog.csdn.net/leftfist/article/details/64439445
https://www.runoob.com/regexp/regexp-syntax.html
https://blog.csdn.net/zzti_erlie/article/details/89842391
http://www.cnblogs.com/mayidudu/p/5885113.html
http://www.cnblogs.com/manongxiaobing/p/9835611.html
https://blog.csdn.net/qq_38111015/article/details/80416823