note 76326 deleted from function.preg-match by tularis

From: Date: Thu, 03 Jul 2008 21:39:14 +0000
Subject: note 76326 deleted from function.preg-match by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141146@lists.php.net to get a copy of this message
Note Submitter: David W. ---- I just started using PHP and this section doesn't clarify whether or not you must use "/" as your regular expression delimiters. I want to clarify that you can use almost any character as your delimiter. The delimiter is automatically the first character of your regular expression string. This makes it a bit easier if you are looking for things that might contain a forward slash. For example:: preg_match('#</b>#', $string); Instead of: preg_match('/<\/b>/', $string); Or: preg_match('@/my/dir/name/@', $string); Instead of: preg_match('/\/my\/dir\/name\//', $string); This can greatly boost readability. Not quite as flexible as in Perl (You can't use control characters or \n which can really come in handy when you aren't quite sure what characters might be in your regular expression), but switching to another delimiter can make your code a bit easier to read.

« previous php.notes (#141146) next »