regex - PHP: preg_replace() on NameSpace -
i'm trying parent "elements" name string php namespace in string, ideia do:
input: \base\util\review
; desired output: \base\util
;
my main problem here how can deal backslash escaping in regex expression, far can make work normal slash:
$ns = "/base/util/review"; print preg_replace("#\/[^/]*$#", '', $ns); // outputs => /base/util
thank you.
this should work:
$s = '\\base\\util\\review'; $r = preg_replace('~\\\\[^\\\\]*$~', '', $s); //=> \base\util
Comments
Post a Comment