我认为扩展字符类会阻止轮子的重新发明,所以我扩展了它。
用法
电子邮件地址
'foo@example.com'.match(/x{email}/g)
// ['foo@example.com']
网址
'https://example.com/foo/bar'.match(/x{url}/g)
// ['https://example.com/foo/bar']
都道府县
'島根県にパソコンなんてあるわけないじゃん'.match(/x{都道府県}/g)
// ['島根県']
IP地址
'127.0.0.1'.match(/x{ip}/g)
// ['127.0.0.1']
全域名
'example.com sub.example.com'.match(/x{fqdn}/g)
// ['example.com', 'sub.example.com']
地方
const str = '時どき私はそんな路を歩きながら、ふと、そこが京都ではなくて京都から何百里も離れた仙台とか長崎とか――そのような市へ今自分が来ているのだ――という錯覚を起こそうと努める。'
await str.matchAsync(/x{場所}/g)
// ['京都', '京都', '仙台', '長崎']
人
await '昨日、ジョンと山田太郎は松のやでカツ丼を食した。'.matchAsync(/x{人物}/g)
// ['ジョン', '山田太郎']
安装
npm install cc-regex
浏览器
<script src="https://github30.github.io/cc-regex/index.js">
原创声明:本文系作者授权爱码网发表,未经许可,不得转载;
原文地址:https://www.likecs.com/show-308623432.html