什么是“最好”的方式来匹配一个字符串中的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)' –