Re: Unable to match dollar sign in preg_match

From: Date: Tue, 24 Dec 2002 12:04:52 +0000
Subject: Re: Unable to match dollar sign in preg_match
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-129279@lists.php.net to get a copy of this message
John W. Holmes wrote:
I don't know. I just got that from reading the manual. The very first user comment on the preg_match page.
to put a literal dollar sign in a regex it has to be escaped \$ to put a backslash in a double quoted string you have to escape it \\$ in order to put a literal dollar sign in a double quoted string you have to escape it \\\$ or you can use sinlgle quotes - where you only have to escape the dollar sign once to mark it a a literal dollar sign and not an end string/line placeholder preg_match('/\$example/' , $matchme)) Sean
---- chrisbolt at home dot com 12-Mar-2000 03:23 If you want to use some of PHP's special characters in your expression, such as $, you must escape it twice. For example: $matchme = "\$example"; if (preg_match("/\$example/", $matchme)) { will not be matched because PHP interprets the \$ and passes it as $. Instead, you must do this: if (preg_match("/\\\$example/", $matchme)) { --- Don't forget to check the manual. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/
-----Original Message----- From: Randall Perry [mailto:rgp@systame.com] Sent: Monday, December 23, 2002 4:07 PM To: php-general@lists.php.net Subject: Re: [PHP] Unable to match dollar sign in preg_match Hokay, that works, but what's with the triple backslashes?
preg_match ("/^.*_\%split\%_$(\d*\.\d*)/", $data, $match);
Should be preg_match ("/^.*_\%split\%_\\\$(\d*\.\d*)/", $data, $match); ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your
copy
today. http://www.phparch.com/
-- Randall Perry sysTame Xserve Web Hosting/Co-location Website Development/Promotion Mac Consulting/Sales http://www.systame.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#129279) next »