需要正则表达式才能在字符串中搜索


Need regular expression to search inside string

如果逗号在||和||中多次出现,我需要正则表达式来搜索逗号,并返回||和||之间的字符串。例如,考虑这个字符串:

$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代码中使用它。

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 = "";
}