資訊中心
百度資源平臺(tái)正則格式示例
1、純數(shù)字替換生成pattern例子:
eg1:url對(duì)應(yīng)關(guān)系:
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ì)應(yīng)關(guān)系:
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ì)應(yīng)關(guān)系:
http://www.abc.com/fawliute/?->?http://m.abc.com/fawliute/ pattern: http://www.abc.com/([a-zA-Z]+)/?->??http://m.abc.com/${1}/
3、字母和數(shù)字混合的字符串替換生成pattern的例子:
eg1:url對(duì)應(yīng)關(guān)系:
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}/
注意:字母和數(shù)字混合字符串,字母和數(shù)字必須交替出現(xiàn)至少1次
有效例子:a13b,23a9,da3bc99,42a1c
eg2:url對(duì)應(yīng)關(guān)系:
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ì)于字母和數(shù)字只交替出現(xiàn)一次的,可以分別用數(shù)字和字母進(jìn)行正則替換:
eg:url對(duì)應(yīng)關(guān)系:
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ì)應(yīng)關(guān)系:
http://www.abc.com/長(zhǎng)城花園/ -> http://m.abc.com/長(zhǎng)城花園/ pattern: http://www.abc.com/((?:%[a-zA-Z0-9]{2,})+)/-> http://m.abc.com/${1}/
6、由'-'或者'_'連接的數(shù)字或者字母替換生成pattern的例子:
eg:url對(duì)應(yīng)關(guān)系:
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}/
注意:'-'和'_'出現(xiàn)多次可以使用同樣的方式處理 如:abc-134_x-1
7、對(duì)參數(shù)部分進(jìn)行正則替換生成pattern的例子:
eg:url對(duì)應(yīng)關(guān)系:
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存在分頁(yè)對(duì)應(yīng)移動(dòng)頁(yè)面生成pattern的例子:
eg:url對(duì)應(yīng)關(guān)系:
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