以后地位:首页 > 咱们的概念 > 列表

百度挪动适配:正则格局例子

点击: 次时候:2016/3/21关头词:百度正则 挪动适配
1、纯数字替代天生pattern例子:eg1:url对应干系:http://www.abc.com/26299483.html-> http://m.abc.com/26299483.htmlpattern:http://www.abc.com/([0-

1、纯数字替代天生pattern例子:
eg1:url对应干系:

http://www.abc.com/26299483.html->  http://m.abc.com/26299483.html
pattern:
http://www.abc.com/([0-9]+).html->  http://m.abc.com/${1}.html

eg2:url对应干系:

http://www.abc.com/t26299483.html->  http://m.abc.com/26299483.html
pattern:
http://www.abc.com/t([0-9]+).html->  http://m.abc.com/${1}.html

2、纯字母替代天生pattern例子:

eg:url对应干系:

http://www.abc.com/fawliute/ -> http://m.abc.com/fawliute/
pattern:
http://www.abc.com/([a-zA-Z]+)/ ->  http://m.abc.com/${1}/

3、字母和数字夹杂的字符串替代天生pattern的例子:

eg1:url对应干系:

http://www.abc.com/a1cc1n2q5y3/ ->  http://m.abc.com/a1cc1n2q5y3/
pattern:
http://www.abc.com/((?:[a-zA-Z]+[0-9]+|[0-9]+[a-zA-Z]+)[a-zA-Z0-9]+)/   -> http://m.abc.com/${1}/

注重:字母和数字夹杂字符串,字母和数字必须瓜代呈现最少1次

有用例子:a13b,23a9,da3bc99,42a1c

eg2:url对应干系:

http://news.abc.com/09/1001/07/5KH8DE1F000120GR.html
-> http://m.abc.com/news/09/1001/07/5KH8DE1F000120GR.html
pattern:
http://news.abc.com/([0-9]+)/([0-9]+)/([0-9]+)/([ a-zA-Z0-9]+).html
-> http://m.abc.com/news/${1}/${2}/${3}/${4}.html

4、对字母和数字只瓜代呈现一次的,能够别离用数字和字母停止正则替代:

eg:url对应干系:

http://www.abc.com/az123/   ->     http://m.abc.com/az123/
pattern:
http://www.abc.com/([a-zA-Z]+)([0-9]+)/-> http://m.abc.com/${1}${2}/

5、中笔墨符串正则替代天生pattern例子:

eg:url对应干系:

http://www.abc.com/长城花圃/ -> http://m.abc.com/长城花圃/
pattern:
http://www.abc.com/((?:%[a-zA-Z0-9]{2,})+)/-> http://m.abc.com/${1}/

6、由'-'或'_'毗连的数字或字母替代天生pattern的例子:

eg:url对应干系:

http://www.abc.com/byd-c3/-> http://m.abc.com/byd-c3/
pattern:
http://www.abc.com/([a-zA-Z]+)-([a-zA-Z]+)([0-9]+)/->http://m.abc.com/${1}-${2}${3}/

注重:'-'和'_'呈现屡次能够利用一样的体例处置
如:abc-134_x-1

7、对参数局部停止正则替代天生pattern的例子:

eg:url对应干系:

http://www.abc.com/article.html?act=test&id=123  ->        http://m.abc.com/article.html?act=test&id=123
pattern:
http://www.abc.com/article\.html?act=([^&]+)&id=([^&]+)   -> }

8、PC存在分页对应挪动页面天生pattern的例子:

eg:url对应干系:
http://www.a.com/1234-1.htm  http://www.a.com/1234-2.htm   ->http://m.a.com/1234.htm
pattern:
http://www.a.com/([0-9]+)-([0-9]+).htm ->  http://m.a.com/${1}.htm

预定建站
收费供给网站优化
支付关头词