Regular/替换域名:修订间差异
来自康健生活
无编辑摘要 |
|||
| 第1行: | 第1行: | ||
== 取网址 == | |||
方法一: | |||
<syntaxhighlight lang="javascript"> | |||
/(http|https):\/\/([\w.]+\/?)\S*/</syntaxhighlight> | |||
方法二: | |||
<syntaxhighlight lang="javascript"> | |||
/http[s]{0,1}:\/\/([\w.]+\/?)\S*/</syntaxhighlight> | |||
使用 js 提取域名(带协议) | |||
<syntaxhighlight lang="javascript"> | |||
url.replace(/(http[s]{0,1}:\/\/[a-zA-Z0-9.-]+)?.*/i,'$1')</syntaxhighlight> | |||
== PHP == | == PHP == | ||
正则提取的url中的域名以及替换域名的方法 preg_match()和preg_replace() | 正则提取的url中的域名以及替换域名的方法 preg_match()和preg_replace() | ||