index
约 815 字大约 3 分钟
2025-07-31
400电话正则:(?\<content>/\<.*?p>/g(400-\d{4}-\d{3})/\<.*?p>/g?)
400电话正则:(?\<content>/\<.*?p>/g400[016789]\d{6}/\<.*?p>/g?)
800电话正则:(?\<content>/\<.*?p>/g800[0-9]{7}/\<.*?p>/g?)
手机号匹配正则:(?\<content>/\<.*?p>/g1([0-9]{10})/\<.*?p>/g?)
固话匹配正则:(?\<content>/\<.*?p>/g0[0-9]{2,3}-[0-9]{8}/\<.*?p>/g?)
网址匹配正则:(?\<content>/\<.*?p>/g\b(([\w-]+://?|www[.])[^\s()\<>]+(?:[\w\d]+[\w\d]+|([^[:punct:]\s]|/)))/\<.*?p>/g?)
正则表达式匹配URL或者网址
正则表达式很常用,下面是我整理的匹配URL或者网址的一些表达式:
| 正则表达式 | (http|ftp|https)://[\w-]+(.[\w-]+)+([\w-.,@?=%&:/~+#]*[\w-@?=%&/~+#])? | | :--- | :--- | | 匹配 | http://regxlib.com/Default.aspx | http://electronics.cnet.com/electronics/0-6342366-8-8994967-1.html | | 不匹配 | www.yahoo.com |
| 则表达式 | ^\{2}[\w-]+\(([\w-][\w-\s]*[\w-]+[$$]?)∣([\w−][]?)) | | :--- | :--- | | 匹配 | \server\service | \server\my service | \serv_001\service$ | | 不匹配 | \my server\service | \server\ service | \server$\service |
| 正则表达式 | (http|https|ftp)😕/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9-]+.)*[a-zA-Z0-9-]+.[a-zA-Z]{2,4})(:[0-9]+)?(/[/][a-zA-Z0-9.,?'\/+&%$#=~_-@])$ | | :--- | :--- | | 匹配 | http://www.sysrage.net | https://64.81.85.161/site/file.php?cow=moo's |ftp://user:pass@host.com:123 | | 不匹配 | sysrage.net |
| 正则表达式 | ([a-zA-Z]😐\\[/\:?"<>|]+\[/\😗?"<>|]+)(\[/\:?"<>|]+)+(.[^/\😗?"<>|]+)$ | | :--- | :--- | | 匹配 | c:\Test.txt | \server\shared\Test.txt | \server\shared\Test.t | | 不匹配 | c:\Test | \server\shared | \server\shared\Test.? |
| 正则表达式 | ^(http|https|ftp)://([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)@)((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9-]+.)[a-zA-Z0-9-]+.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)(/(|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))* | | :--- | :--- | | 匹配 | http://site.com/dir/file.php?var=moo | https://localhost |ftp://user:pass@site.com:21/file/dir | | 不匹配 | site.com | http://site.com/dir// |
| 正则表达式 | ([a-zA-Z]:)(\[\/:?<>"|](?<![ ]))*(.[a-zA-Z]{2,6})$ | | :--- | :--- | | 匹配 | C:\di___r\fi_sysle.txt | c:\dir\filename.txt | | 不匹配 | c:\dir\file?name.txt |
正则表达式 | ^(a-zA-Z0-9?.)+[a-zA-Z]{2,6}$ |
---|---|
匹配 | regexlib.com |
不匹配 | notadomain-.com |
| 正则表达式 | ^(((ht|f)tp(s?))://)?(www.|[a-zA-Z].)[a-zA-Z0-9-.]+.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(:[0-9]+)*(/(|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))* | | :--- | :--- | | 匹配 | www.blah.com:8103 | www.blah.com/blah.asp?sort=ASC |www.blah.com/blah.htm#blah | | 不匹配 | www.state.ga | http://www.blah.ru |
| 正则表达式 | \b(([\w-]+://?|www[.])[\s()<>]+(?:[\w\d]+[\w\d]+|([[:punct:]\s]|/))) | | :--- | :--- | | 匹配 | http://foo.com/blah_blah | http://foo.com/blah_blah/ | (Something like http://foo.com/blah_blah) | http://foo.com/blah_blah_(wikipedia) | (Something like http://foo.com/blah_blah_(wikipedia)) | http://foo.com/blah_blah. |http://foo.com/blah_blah/. | <http://foo.com/blah_blah> | <http://foo.com/blah_blah/>| http://foo.com/blah_blah, | http://www.example.com/wpstyle/?p=364. | http://?df.ws/123 | rdar://1234 | rdar:/1234 | http://userid:password@example.com:8080 |http://userid@example.com | http://userid@example.com:8080 |http://userid:password@example.com | | 不匹配 | no_ws.example.com | no_proto_or_ws.com | /relative_resource.php |
更新: 2023-04-10 14:53:25
原文: <https://www.yuque.com/seoers/usmmz7/gq9os3>