Dennis
Dennis

Reputation: 8111

what is this delimeter (^) in PHP regular expression functions

I am used to the delimiter of /..../ in regular expressions, and I am used to the symbol ^ being used to indicate the beginning of a string, or the negation when used on a class of characters. So when I came across the line below using ^....^, I was puzzled:

$t = "172,249,L,P";
preg_split("^,^", $t);

What does this mean if anything?

Upvotes: 3

Views: 96

Answers (2)

Andy Lester
Andy Lester

Reputation: 93745

This code:

preg_split("^,^", $t);

is the same as this code:

preg_split("/,/", $t);

The use of ^ as a delimiter for the regular expression, and ^ as a metacharacter within the regular expression, are unrelated.

Upvotes: 0

Dennis
Dennis

Reputation: 8111

You can use several various delimiters for the purposes of not having them be escaped in your particular regexp string:

http://php.net/manual/en/regexp.reference.delimiters.php

Upvotes: 4

Related Questions