#27949 [Opn->Bgs]: preg_match cant match ?
| From: | sniper@php.net | Date: | Sun, 11 Apr 2004 04:07:05 +0000 |
| Subject: | #27949 [Opn->Bgs]: preg_match cant match ? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-57911@lists.php.net to get a copy of this message | ||
ID: 27949
Updated by: sniper@php.net
Reported By: drew at corrupt dot co dot nz
-Status: Open
+Status: Bogus
Bug Type: PCRE related
Operating System: FreeBSD 4.9
PHP Version: 4.3.5
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.
Thank you for your interest in PHP.
RTFM: You need to use double backslashes to quote stuff..
Previous Comments:
------------------------------------------------------------------------
[2004-04-10 21:11:53] drew at corrupt dot co dot nz
Description:
------------
I am trying to match a question mark in PHP using preg_match() with the
following attempt's described in the code section.
Neither work, while following documentation examples.
Reproduce code:
---------------
// String:
$line = "This is pretty much a
[url=\"http://www.wiki.org/?WhatIsAWIki\"]Wiki[/url]
but with a twist
of [BBCode] and a few other site specific [Hacks]";
// Attempt #1:
preg_match_all("/\[(\/?[\w\d\-\_]+(=\"[\w\d\S\s\?]+?\")?)\]/",$line,$parse);
print_r($parse);
// Attempt #2:
preg_match_all("/\[(\/?[\w\d\-\_]+(=\"[\w\d\S\s\\\?]+?\")?)\]/",$line,$parse);
print_r($parse);
Expected result:
----------------
I expected that the values
"url=http://www.wiki.org/?WhatIsAWIki" and
"http://www.wiki.org/?WhatIsAWIki"
would be picked up from the regex
into $parse.
It works with the following PERL one liner:
perl -e '$string = "This is pretty much a
[url=\"http://www.wiki.org/?WhatIsAWIki\"]Wiki[/url]
but with a twist
of [BBCode] and a few other site specific [Hacks]"; @match = $string =~
m/\[(\/?[\w\d\-\_]+(=\"[\w\d\S\s\?]+?\")?)\]/; print "Match: " .
join(",",@match) . "\n"'
Match:
url="http://www.wiki.org/?WhatIsAWIki",="http://www.wiki.org/?WhatIsAWIki"
Actual result:
--------------
Matches nothing.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27949&edit=1