MyBB Community Forums

Full Version: PREG pattern syntax
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been looking at various plugins and all the ones that I've seen that uses a PREG function tends to use hashes (#) around their pattern as opposed to slashes (/) whichs is what I see in most examples on php.net.

Is there a specific reason for this or is it still personal preference?
The reason is usually that if you try to match things with / in them, if / is also your pattern separator, you are in escape hell. I.e. it is easier to match #http://site/# than /http:\/\/site\// especially if within a PHP string you might have to write it as "/http:\\/\\/site\\//".

The fact that PHP uses pattern separators within a string is completely braindead in the first place. The pattern modifier should be a separate parameter, not encoded into the string itself in such a broken way. But that's PHP for you.
Great! Thanks frostschutz. I thought about this, but wasn't sure.