开发中总能遇到很多需要正则表达式的地方,这里记录一些,方便查阅。
判断html标签类
标题 head => title
1 | /<TITLE>([\w\W]*?)<\/TITLE>/si |
关键字 head => keywords
因为不能确定位置和符号,所以用了四个来覆盖所有情况。
1 | /<META\s+name="keywords"\s+content="([\w\W]*?)"/si |
描述 head => description
1 | /<META\s+name="description"\s+content="([\w\W]*?)"/si |
判断完整连接
1 | /(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/ |
获取连接的协议加域名部分
1 | /(http|https):\/\/[^\/]+\//i |