php - How to get a portion of a string with a regular expression -


i have situation can have strings this:

"project\\v1\\rest\\car\\controller" "project\\v1\\rest\\boat\\controller" "project\\action\\truck" "project\\v1\\rest\\helicopter\\controller" "parental\\boat\\action" 

just in case string follow pattern:

"project\\v1\\rest\\the_desired_word\\controller" 

i want the_desired_word.

that's why i'm thinking in regular expression.

to use regular expression, need escape slash twice : once php string , once regex

try :

$tab = array(     "project\\v1\\rest\\car\\controller",     "project\\v1\\rest\\boat\\controller",     "project\\v1\\rest\\helicopter\\controller",     "project\\v1\\rest\\water\\controller", );  foreach ($tab $s) {     preg_match("!\\\\([^\\\\]*)\\\\controller!u", $s, $result);     var_dump($result); } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -