我有一個網址爲:正則表達式來與破折號的URL選擇值( - )
http://www.working-test.com/first-second-third-star,LG語言重複,區域-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由於
......怎麼樣'( [^ - ] +?) - (? [^ - ] +) - (? [^ - ] +) - 住所... ...? –
JimmyB
@HannoBinder:謝謝,但我想一直保持STATION-L-CITY的主機3,在這裏它拆分了主機3 http://regex101.com/r/cR1uD2 – TrangZinita
'http:// www \ .working -test.com/first-second-third-star,(? [AZ - 。] +),(?。+) - (? [^ - ] + - [^ - ] + - [^ - ] +) - 住所\ .html#住所' –
JimmyB