phpregexdelimiter

What does it mean when pipe characters are used at the start and end of a regular expression?


Can someone help me understand the following php regex expression. preg_match("|store:(.*)|", $k, $matches) In PHP regex expressions what does the '|' represent?

$storevals = array();
foreach ($item as $k => $v)
{
    if (preg_match("|store:(.*)|", $k, $matches))
    {
        $storevals[$matches[1]] = $v;
    }
}

Previous to this function is a call to convert a CSV file to an array($item) with the csv headers being the keys to the array. Basically I'm trying to figure out the format for the CSV file.


Solution

  • Here is a thorough explanation -

    store: matches the characters "store:" literally (case sensitive) 1st capturing group (.*) (grouped by parentheses) .* matches any character (except newline) Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]

    The pipes | are delimiters for the regex.