note 118835 added to regexp.reference.meta

From: Date: Sat, 13 Feb 2016 09:41:43 +0000
Subject: note 118835 added to regexp.reference.meta
Groups: php.notes 
Request: Send a blank email to php-notes+get-204935@lists.php.net to get a copy of this message
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 ---- 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/118835 Del: integrated -- https://master.php.net/note/delete/118835/integrated Del: useless -- https://master.php.net/note/delete/118835/useless Del: bad code -- https://master.php.net/note/delete/118835/bad+code Del: spam -- https://master.php.net/note/delete/118835/spam Del: non-english -- https://master.php.net/note/delete/118835/non-english Del: in docs -- https://master.php.net/note/delete/118835/in+docs Del: other reasons-- https://master.php.net/note/delete/118835 Reject -- https://master.php.net/note/reject/118835 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204935) next »