note 25291 deleted from function.preg-replace by sniper

From: Date: Fri, 17 Oct 2003 03:53:39 +0000
Subject: note 25291 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58738@lists.php.net to get a copy of this message
Note Submitter: frauen_at_kapierich_dot_net ---- ~~~ \n Characters in search strings: ~~~ It IS possible to use PCRE with \n characters inside the search string, just use the modifier /m for "multiline mode" (I too pulled some hair out to figure out that one, just read _carefully_ about PCRE Synthax) ~~~ Numbers following \\# ~~~ I experienced some problems with adding a date to a filename. The RegExp checked for any given directory before the filename, then looked up if there were 8 numbers (a date of YYYYMMDD), a - and a filename.php If the 8 numbers don't exist it adds them automatically: $Ymd_date = date('Ymd'); $regExp_3 = '/^(\/(.*\/)+?)([^\d]{8})(.*\.php)$/i'; $replacement_3 = "\\1".$Ymd_date.'-\\3\\4'; You would assume that it would replace \\1 to everything inside the first (), but no - adding a number (the date) it actually looks like this to the parser: "\\120020918-\\3\\4" The parser must think you're using \\12 ! I fixed that with a workaround: $Ymd_date = date('Ymd'); $regExp_3 = '/^(\/(.*\/)+?)([^\d]{8})(.*\.php)$/i'; $replacement_3 = "\\1_%_%_".$Ymd_date.'-\\3\\4'; Another str_replace('_%_%_','',$string); to the string preg_replace returned did it (unlikely to have _%_%_ in the filename).

« previous php.notes (#58738) next »