1、純數字替換生成pattern例子:
eg1:url對(duì)應關系:
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對(duì)應關系:
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對(duì)應關系:
http://www.abc.com/fawliute/ -> http://m.abc.com/fawliute/
pattern:
http://www.abc.com/([a-zA-Z]+)/ -> http://m.abc.com/${1}/
3、字母和(hé)數字混合的(de)字符串替換生成pattern的(de)例子:
eg1:url對(duì)應關系:
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}/
注意:字母和(hé)數字混合字符串,字母和(hé)數字必須交替出現至少1次
有效例子:a13b,23a9,da3bc99,42a1c
eg2:url對(duì)應關系:
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、對(duì)于字母和(hé)數字隻交替出現一次的(de),可(kě)以分(fēn)别用(yòng)數字和(hé)字母進行正則替換:
eg:url對(duì)應關系:
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對(duì)應關系:
http://www.abc.com/長(cháng)城(chéng)花園/ -> http://m.abc.com/長(cháng)城(chéng)花園/
pattern:
http://www.abc.com/((?:%[a-zA-Z0-9]{2,})+)/-> http://m.abc.com/${1}/
6、由'-'或者'_'連接的(de)數字或者字母替換生成pattern的(de)例子:
eg:url對(duì)應關系:
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}/
注意:'-'和(hé)'_'出現多(duō)次可(kě)以使用(yòng)同樣的(de)方式處理(lǐ)
如:abc-134_x-1
7、對(duì)參數部分(fēn)進行正則替換生成pattern的(de)例子:
eg:url對(duì)應關系:
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=([^&]+) -> http://m.abc.com/article.html?act=${1}&id=${2}
8、PC存在分(fēn)頁對(duì)應移動頁面生成pattern的(de)例子:
eg:url對(duì)應關系:
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