note 118345 added to function.preg-match-all

From: Date: Thu, 19 Nov 2015 14:31:00 +0000
Subject: note 118345 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-204191@lists.php.net to get a copy of this message
I had been crafting and testing some regexp patterns online using the tools Regex101 and a preg_match_all() tester and found that the regexp patterns I wrote worked fine on them, just not in my code. My problem was not double-escaping backslash characters: <?php // Input test $input = "\"something\",\"something here\",\"some\nnew\nlines\",\"this is the end\""; // Work with online regexp testers, doesn't work in PHP preg_match_all( "/(?:,|^)(?<!\\)\".*?(?<!\\)\"(?:(?=,)|$)/s", $input, $matches ); /* Outputs: NULL */ // Works with online regexp testers, does work in PHP preg_match_all( "/(?:,|^)(?<!\\\\)\".*?(?<!\\\\)\"(?:(?=,)|$)/s", $input, $matches ); /* Outputs: array(2) { [0]=> array(4) { [0]=> string(11) ""something"" [1]=> string(17) ","something here"" [2]=> string(17) ","some new lines"" [3]=> string(18) ","this is the end"" } [1]=> array(4) { [0]=> string(9) "something" [1]=> string(14) "something here" [2]=> string(14) "some new lines" [3]=> string(15) "this is the end" } } */ ?> ---- Server IP: 72.52.91.14 Probable Submitter: 85.68.38.114 ---- Manual Page -- http://php.net/manual/en/function.preg-match-all.php Edit -- https://master.php.net/note/edit/118345 Del: integrated -- https://master.php.net/note/delete/118345/integrated Del: useless -- https://master.php.net/note/delete/118345/useless Del: bad code -- https://master.php.net/note/delete/118345/bad+code Del: spam -- https://master.php.net/note/delete/118345/spam Del: non-english -- https://master.php.net/note/delete/118345/non-english Del: in docs -- https://master.php.net/note/delete/118345/in+docs Del: other reasons-- https://master.php.net/note/delete/118345 Reject -- https://master.php.net/note/reject/118345 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204191) next »