PatRoy Posted March 9, 2020 Share Posted March 9, 2020 (edited) Hello, I'm sure my error isn't much, but I can't seem to remove part of a string... This is an example string: Stack trace: #0 /mnt/HD/HD_a2/DATA/WWW/html/calchom/include/CorbeauPerdu/Database/DBWrapperStatement.php(525): CorbeauPerdu\Database\DBWrapperStatement->_stmtCommitOnEachExec_HOTFIX() #1 /mnt/HD/HD_a2/DATA/WWW/html/calchom/include/CorbeauPerdu/Database/DBWrapperStatement.php(378): CorbeauPerdu\Database\DBWrapperStatement->_runMultiStatement(true) #2 /mnt/HD/HD_a2/DATA/WWW/html/calchom/include/CorbeauPerdu/Database/DBWrapper.php(773): CorbeauPerdu\Database\DBWrapperStatement->runStatement(false, true) #3 /mnt/HD/HD_a2/DATA/WWW/html/calchom/include/CorbeauPerdu/Database/DBWrapper.php(708): CorbeauPerdu\Database\DBWrapper->_storeDataEXE('INSERT INTO tbl...', Array, Array, true) #4 /mnt/HD/HD_a2/DATA/WWW/html/calchom/test.php(112): CorbeauPerdu\Database\DBWrapper->storeData('INSERT INTO tbl...', Array, Array, true, true) #5 {main} I want to remove, in this case, all instances of "CorbeauPerdu\Database\" . These could be other words of course... I tried the following regex in preg_replace(), which seems to work if I test in http://regex101.com/, but doesn't seem to work at all: $pattern = "/\w+\\\w+\\/"; echo "Fixed = ".preg_replace($pattern, "", $str); On top of that, my error log keeps telling me: Warning: preg_replace(): No ending delimiter '/' found ... Any ideas on what I'm doing wrong here? Much thanks Pat Edited March 9, 2020 by PatRoy Quote Link to comment https://forums.phpfreaks.com/topic/310239-warning-preg_replace-no-ending-delimiter-found/ Share on other sites More sharing options...
requinix Posted March 9, 2020 Share Posted March 9, 2020 regex101.com doesn't know that you're trying to put the regex into a PHP string. Escape the backslashes. Quote Link to comment https://forums.phpfreaks.com/topic/310239-warning-preg_replace-no-ending-delimiter-found/#findComment-1575311 Share on other sites More sharing options...
PatRoy Posted March 9, 2020 Author Share Posted March 9, 2020 3 hours ago, requinix said: regex101.com doesn't know that you're trying to put the regex into a PHP string. Escape the backslashes. Thanks. I had to escape 3 times the backslach afterall : preg_replace("/\w+\\\/", "", $str); Cheers for your help Quote Link to comment https://forums.phpfreaks.com/topic/310239-warning-preg_replace-no-ending-delimiter-found/#findComment-1575319 Share on other sites More sharing options...
requinix Posted March 9, 2020 Share Posted March 9, 2020 The basic process is, if you want literal backslashes in a regex then you need to double it to make PCRE happy, then double it again to make PHP happy. 1 Quote Link to comment https://forums.phpfreaks.com/topic/310239-warning-preg_replace-no-ending-delimiter-found/#findComment-1575320 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.