What does it mean when Regex starts with |?
Here's an example:
return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?
(/.*)?$|i', $url);
Here's another one:
preg_match_all("|<[^>]+>(.*)</[^>]+>|U", "<b>example: </b><div align=left>this is a test</div>", $out, PREG_PATTERN_ORDER);
This is not | a OR in Regex? What does it mean when a regular expression starts with |?
source to share
It uses it as a regex delimiter, which is an extremely bad idea as it doesn't allow it to be used as an OR operator.
While it makes sense not to use it /
when dealing with URLs or anything else where slashes are often used (since every normal slash /
must be escaped as \/
in this case), it is usually much better for use, for example, #
or ~
as a separator, since they are are normal characters in the regex itself.
source to share