什麼是「最好」的方式來匹配一個字符串中的URL,該字符串中有很多逗號(,,,,,),並且可能在404字符串後面有分隔符昏迷。在404字符串到來之後,獲取字符串直到這部分。正則表達式 - 直到
例子:
http://stackoverflow.com/this,,,can,be,,a,slug,,,0,404
或
http://stackoverflow.com/this,,,can,be,,a,slug,,,0
我得:http://stackoverflow.com/this,,,can,be,,a,slug,,,0
嘗試這些:
^(.*)(\,404)?
[^,404]*
如果沒有404字符串會怎麼樣? –
@ R.CanserYanbakan嘗試像這樣修改:[^。*?(?=,404 | $)](http://regex101.com/r/zL1rX0)...添加開始錨點,量詞[greedy] (http://www.rexegg.com/regex-greed.html)並添加OR end-anchor到'(?=,404)' –