Hi all! Kore and me just had an interessting discussion about the delimiter characters to be used in PCRE statements. The most common way (at least what I experienced) is to use slashes as delimiters, which results in constructs like the following one:
preg_match( '/foo.*bar/i', $subj, $matches ); In case I need to use a slash inside the regex itself, I need to escape it, thought. Therefore, if I know I need multiple slashes inside the regex, I tend to switch the delimiters to @ chars, to save me from escaping slashes. Still, then I need to escape any @ inside the regex: preg_match( '@/foo/[EMAIL PROTECTED]@i', $subj, $matches ); Kore just told me, that he has switched to using normal braces as delimiters, which I did not know to be working at all: preg_match( '(/foo/[EMAIL PROTECTED])i', $subj, $matches ); While this looks strange (at least to me) at the first glance, using braces seems to have several advantages over all other characters: - You don't need to escape braces inside the regex, if you use braces as a delimiter, resulting in no more silly escaping of the delimiter chars at all. - In $matches[0] the whole match is saved, while all higher indexes contain deeper matching braces. Using braces as delimiters make this behaviour more logical. While I'm almost convinced of using braces, I want to hear your opinions here. Kore and me want to use that style of delimiting regex in Webdav and I'm also thinking about migrating my other components regexes (if there are any). Any comments? Regards, Toby -- Mit freundlichen Grüßen / Med vennlig hilsen / With kind regards Tobias Schlitt (GPG: 0xC462BC14) eZ Components Developer [EMAIL PROTECTED] | eZ Systems AS | ez.no -- Components mailing list [email protected] http://lists.ez.no/mailman/listinfo/components
