2015-10-06 21 views
0

我試圖完成的情況下路徑尋找像這樣的:匹配所有字符串,直到指定了一個發生在urlrewrite.xml

http://verylongpath.com/show.html,a1,b2,c3,stop,d4,e5

將得到改寫爲

path = a1 & attributes = b2,c3 & splitters = d4,e5

(或更像 somepath.html?路徑= 1個&屬性= $ [numberOfGroup] &分路器= $ [numberOfGroup])

到目前爲止,我已經成功地創造這樣

<from>^/(?!whatever/)(.*),a([0-9]+)(,(.+))?.html(\?(.*))?$</from> 
<to last="true">somepath.html?path=$2&amp;attributes=$4&amp;$6</to> 

其明顯我有改變這部分代碼:

(,(.+)) 

具有的含義:每個字符串匹配(例如:B3,C56,e12345)分裂b直到你遇到特定的字符串(「停止」),然後保持匹配,直到你遇到'。'。

我試着在

<from>^/(?!whatever/)(.*),a([0-9]+)(,(.?!(?=stop)))?,stop(,(.+))?.html(\?(.*))?$</from> 

沒有成功的結果使用

(,(.+?(?=stop)))? 

,如 '停' 還是會被匹配作爲一個正常的字符串,我rewroten URL看起來像這樣:

"somepath.html?path=54&attributes=a1,b2,c3,stop,d4,e5&" 

如果有人引導我進入有效的解決方案,我將不勝感激。

回答

1

嘗試下面的表達式中from標籤:

^[^,]+,(a[0-9]+),(.*?),stop,?(.*)$ 

請注意,這是一個非常通用的表達。上面沒有花哨的比賽/小組。如果有任何匹配的組是可選的,則使用?來使它們成立。現在

,在重寫URL:

somepath.html?path=$1&attributes=$2&splitters=$3 
相關問題