附录2 常用正则表达式
- · -
邮箱
[\w-](\.?[\w-]+)+@[\w-]+(\.[\w-]+)+
123@123.cn 1a2b3c_efd@123.com.cn 123@abc.cn 123@abc.org.cn 123.123@123.cn 123.abc.__@123.cn
IPV4 地址
(25[0-5]|2[0-4]\d|1\d{2}|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d{2}|\d{1,2})){3}
127.0.0.1 192.168.1.1 192.168.3.222 123.45.6.78 255.255.255.255 999.999.999.999
身份证号
前面的区域码并没有直接在模式里面考虑到所有的情况,可以把符合格式的查找出来以后再用程序判断逻辑上是否合法。
(?<district>[1-8][1-7]\d{4})(?<birthday>(?<year>1\d{3})(?<month>[01]\d)(?<day>[01]\d))(?<code>\d{3})(?<verify>[\dxX])
371422196603104039 632122198501102814 342128196203036214 432524198805160033 432822197502078293 440823197509072712
手机号
(\+86)?1\d{10}
13800000000 13200000001 17800000001 19800000001 +8617800000001 +8619800000001
A 标签
<a.*?href=['"](?<link>.*?)['"]>(?<content>.*?)</a>
<div> <ul class="cool-row" monkey="row0"> <!-- 各种视频 --> <li class="site-item first"><a href="http://v.hao123.baidu.com/">视频</a></li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://haokan.baidu.com/" data-title="好看视频">好看视频</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://www.iqiyi.com/" data-title="爱奇艺高清">爱奇艺高清</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://v.qq.com/" data-title="腾讯视频">腾讯视频</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://live.baidu.com/?source=hao123" data-title="百度直播">百度直播</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://www.youku.com/" data-title="优酷网">优酷网</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://www.mgtv.com/" data-title="芒果TV">芒果TV</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://v.baidu.com/" data-title="百度视频">百度视频</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://tv.sohu.com/" data-title="搜狐视频">搜狐视频</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://v.hao123.baidu.com/dianying" data-title="最新影视">最新影视</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://quanmin.baidu.com/" data-title="全民小视频">全民小视频</a></div> </li> <li class="site-item last" monkey="more"><a href="http://v.hao123.baidu.com/">更多>></a></li> </ul> </div>
网址
(https?:)?//[\w\-%/\.]+(:\d{1,5})?(\?([\w&=%\-]+)?)?
<div> <ul class="cool-row" monkey="row0"> <!-- 各种视频 --> <li class="site-item first"><a href="http://v.hao123.baidu.com/">视频</a></li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://haokan.baidu.com/" data-title="好看视频">好看视频</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://www.iqiyi.com/" data-title="爱奇艺高清">爱奇艺高清</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://v.qq.com/" data-title="腾讯视频">腾讯视频</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://live.baidu.com/?source=hao123" data-title="百度直播">百度直播</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://www.youku.com/" data-title="优酷网">优酷网</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://www.mgtv.com/" data-title="芒果TV">芒果TV</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://v.baidu.com/" data-title="百度视频">百度视频</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://tv.sohu.com/" data-title="搜狐视频">搜狐视频</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://v.hao123.baidu.com/dianying" data-title="最新影视">最新影视</a></div> </li> <li class="site-item"> <div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://quanmin.baidu.com/" data-title="全民小视频">全民小视频</a></div> </li> <li class="site-item last" monkey="more"><a href="http://v.hao123.baidu.com/">更多>></a></li> </ul> </div>
代码注释
(//\s?.*)|(/\*(\s|.)*?\*/)
// Hash计算工具 export const Hash = { /** * 计算文本的SM3 * @param input 要计算SM3的文本 * @returns 16进制SM3值文本 */ async sm3(input: string): Promise<string> { // 动态加载sm3计算库,在不使用时不加载 const func = (await import("sm3")).default; return func(input); }, };
HTML 注释
<!-{2,}(.*?)-{2,}>
<div>
<ul class="cool-row" monkey="row0">
<!-- 各种视频 -->
<li class="site-item first"><a href="http://v.hao123.baidu.com/">视频</a></li>
<li class="site-item">
<div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://haokan.baidu.com/"
data-title="好看视频">好看视频</a></div>
</li>
<li class="site-item">
<div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://www.iqiyi.com/"
data-title="爱奇艺高清">爱奇艺高清</a></div>
</li>
<li class="site-item">
<div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://v.qq.com/"
data-title="腾讯视频">腾讯视频</a></div>
</li>
<li class="site-item">
<div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://live.baidu.com/?source=hao123"
data-title="百度直播">百度直播</a></div>
</li>
<li class="site-item">
<div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://www.youku.com/"
data-title="优酷网">优酷网</a></div>
</li>
<li class="site-item">
<div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://www.mgtv.com/"
data-title="芒果TV">芒果TV</a></div>
</li>
<li class="site-item">
<div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://v.baidu.com/"
data-title="百度视频">百度视频</a></div>
</li>
<li class="site-item">
<div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://tv.sohu.com/"
data-title="搜狐视频">搜狐视频</a></div>
</li>
<li class="site-item">
<div class="inline-block-wrapper"><a class="sitelink icon-site" href="http://v.hao123.baidu.com/dianying"
data-title="最新影视">最新影视</a></div>
</li>
<li class="site-item">
<div class="inline-block-wrapper"><a class="sitelink icon-site" href="https://quanmin.baidu.com/"
data-title="全民小视频">全民小视频</a></div>
</li>
<li class="site-item last" monkey="more"><a href="http://v.hao123.baidu.com/">更多>></a></li>
</ul>
</div>
待补充
该内容为何方原创,转载请注明本页地址
https://iamhefang.cn/tutorials/正则表达式/附录2-常用正则表达式