2014-04-17 40 views
0

我有一個網址爲:正則表達式來與破折號的URL選擇值( - )

http://www.working-test.com/first-second-third-starLG語言重複,區域-STATION-L-CITY -residence.html#住宅

與正則表達式模式如下:http://regex101.com/r/hW9eK8

http://www\.working-test.com/first-second-third-star,(?<Host>[A-Z-.]+),(?<Host2>\w-?\w+)-(?<Host3>[A-Z-.]+)-residence\.html#residence

我可以匹配:

MATCH 1

主機[52-70] LG-Language-repeat

主機2 [71-77] region

主機3 [78-92] STATION-L-CITY

但在主機2有時會出現1或2個以上的短劃線( - )符號,例如「region-ABC-STATION-L-CITY」,則上述模式無法工作。

所以我希望在任何情況下,我們總是可以不管有多少破折號(S),我們在主機2(區域或區域-AB)

站-L-CITY單獨作爲主機3由於

+0

......怎麼樣'( [^ - ] +?) - (? [^ - ] +) - (? [^ - ] +) - 住所... ...? – JimmyB

+0

@HannoBinder:謝謝,但我想一直保持STATION-L-CITY的主機3,在這裏它拆分了主機3 http://regex101.com/r/cR1uD2 – TrangZinita

+0

'http:// www \ .working -test.com/first-second-third-star,(? [AZ - 。] +),(?。+) - (? [^ - ] + - [^ - ] + - [^ - ] +) - 住所\ .html#住所' – JimmyB

回答

0

這不工作:(修改)

此處參考檢查:

regex101.com/r/lZ5aM4

+0

謝謝,但與你的模式,主機3不是STATION-L-CITY,我希望保持主機3作爲STATION-L-CITY儘管有多少破折號在主機2中。你的模式:http://regex101.com/r/lL8dJ7 – TrangZinita

+0

根據你的評論修改,現在檢查。 –

+0

plz不要只是連接到外部頁面,但包括什麼是必要的,以回答您的文章中的問題呢! – DrCopyPaste

相關問題