note 118854 modified in regexp.reference.meta by cmb

From: Date: Thu, 18 Feb 2016 11:32:36 +0000
Subject: note 118854 modified in regexp.reference.meta by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-204979@lists.php.net to get a copy of this message
disturbing usage of "any character" for multi-lines... 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* --was-- 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* http://php.net/manual/en/regexp.reference.meta.php

« previous php.notes (#204979) next »