如果在||中出现多次,我需要正则表达式来搜索逗号和||并在||之间返回字符串和||。例如。考虑这个字符串:
$str = "http://www.test.com||abd-asd,asf,asfdsf[asf[s]asf,http://www.test1.com||asfsaf";
所以在上面的字符串上运行正则表达式之后,它应该返回:
abd-asd,asf,asfdsf[asf[s]asf,http://www.test1.com
不包括||和||。我必须在我的PHP代码中使用它。
答案 0 :(得分:1)
if (preg_match(
'/(?<=\|\|) # Assert starting position directly after ||<
[^,|]*, # Match any number of characters except , or |; then a ,
[^,|]*, # twice (so we have matched at least two commas)
[^|]* # Then match anything except | characters
(?=\|\|) # until we are right before ||
/x',
$subject, $regs)) {
$result = $regs[0];
} else {
$result = "";
}