note 118854 added to regexp.reference.meta
| From: | KurtWei | Date: | Wed, 17 Feb 2016 10:43:30 +0000 |
| Subject: | note 118854 added to regexp.reference.meta | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204965@lists.php.net to get a copy of this message | ||
disturbing usage of "any character" for multi-lines...
(@developers: this comment should substitute my previous comment on missing the correct solution -
please delete the old comment)
remark:
'.' (all characters) just does NOT include on single character the newline (\n) by
default,
while \n is included in all other matching searches (e.g. \s).
Funny enough, the "carriage return" (\r) is included, when using '.'
You have to write "(.|\\n)" instead of a single dot, with disadvantages in using complex
matching-results,
or simple use the "s" modificator to bring dot to accept the newline.
$subject="<tag>Hello\nWorld</tag>";
preg_match( '/<tag>[A-Za-z\\s]*<\\/tag>/' , $subject ); //true
preg_match( '/<tag>[^<]*<\\/tag>/' , $subject ); //true
preg_match( '/<tag>(.|\\n)*<\\/tag>/' , $subject ); //true
preg_match( '/<tag>.*<\\/tag>/s' , $subject ); //true
preg_match( '/<tag>.*<\\/tag>/' , $subject ); //ATTENTION! *false*
----
Server IP: 72.52.91.14
Probable Submitter: 91.114.64.156
----
Manual Page -- http://php.net/manual/en/regexp.reference.meta.php
Edit -- https://master.php.net/note/edit/118854
Del: integrated -- https://master.php.net/note/delete/118854/integrated
Del: useless -- https://master.php.net/note/delete/118854/useless
Del: bad code -- https://master.php.net/note/delete/118854/bad+code
Del: spam -- https://master.php.net/note/delete/118854/spam
Del: non-english -- https://master.php.net/note/delete/118854/non-english
Del: in docs -- https://master.php.net/note/delete/118854/in+docs
Del: other reasons-- https://master.php.net/note/delete/118854
Reject -- https://master.php.net/note/reject/118854
Search -- https://master.php.net/manage/user-notes.php