note 118835 deleted from regexp.reference.meta by cmb
| From: | cmb@php.net | Date: | Thu, 18 Feb 2016 11:32:18 +0000 |
| Subject: | note 118835 deleted from regexp.reference.meta by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-204978@lists.php.net to get a copy of this message | ||
Note Submitter: Kurt Wei
----
disturbing usage of "any character" for multi-lines...
. (all characters) just does NOT include on single character the newline (\n) while \n is included
in all other matching searches (e.g. \s)
funny enough, the "carriage return" (\r) is included in "."
You have to write "(.|\\n)" instead of a single dot.
This workaround can have disadvantages when using complex matching results.
Another possible workaround (when using "linux style" text) will be to replace all \n to
\r before search and re-replace after.
$subject="<tag>Hello World</tag>";
preg_match('/<tag>[A-Za-z\\s]*<\\/tag>/',$subject); //true
preg_match('/<tag>[^<]*<\\/tag>/',$subject); //true
preg_match('/<tag>.*<\\/tag>/',$subject); /true
preg_match('/<tag>(.|\\n)*<\\/tag>/',$subject); //true
$subject="<tag>Hello\nWorld</tag>";
preg_match('/<tag>[A-Za-z\\s]*<\\/tag>/',$subject); //true
preg_match('/<tag>[^<]*<\\/tag>/',$subject); //true
preg_match('/<tag>.*<\\/tag>/',$subject); //*false*
preg_match('/<tag>(.|\\n)*<\\/tag>/',$subject); //true