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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -