-1

i have full string like this:

Route::post('asdasdasdad/{param1}/{param2}', 'Admin\RouteController@a212e12e');.

and want to delete that route so in preg_replace i focus on

Route::post('asdasdasdad as start text and

Admin\RouteController@a212e12e'); as last text.

here what i try

preg_replace("/Route::post('asdasdasdad\(.*Admin\RouteController@a212e12e');\s*/s", "", $string);

but its not working.

3
  • For starters, you seem to be escaping stuff in the wrong places. post( - the brace at the end here is supposed to be a literal one, so that one would have to be escaped. asdasdasdad\( - and here you are escaping it, meaning this demands a literal ( in that place, which isn’t present in your data.
    – misorude
    Aug 8, 2019 at 9:06
  • “and want to delete that route” - meaning what, exactly? What is the exact desired result for the given input?
    – misorude
    Aug 8, 2019 at 9:08
  • i want to delete all of this Route::post('asdasdasdad/{param1}/{param2}', 'Admin\RouteController@a212e12e');.
    – Jazuly
    Aug 8, 2019 at 9:15

1 Answer 1

1

you have some errors in your regex, some un-escaped regex characters. try this

preg_replace("/Route::post\('asdasdasdad.*Admin\\\\RouteController@a212e12e'\);\s*/s", "", $string); 

if you want to replace multiple lines in one go

preg_replace_all("/Route::post\('asdasdasdad.*Admin\\\\RouteController@a212e12e'\);\s*/s", "", $string); 

witch works as if you add the multi line modifier to your regex

$string = file_get_contents('route.php');
$string = preg_replace("/Route::post\('asdasdasdad.*Admin\\\\RouteController@a212e12e'\);\s*/s", "", $string);
echo $string;

you get the line with EOL removed

4
  • @Jazuly can you provide the full route file and mark the routes you're trying to remove ?
    – N69S
    Aug 8, 2019 at 9:32
  • @Jazuly wich lines re supposed to be removed? i dont see any significative markings. can you provide line numbes ?
    – N69S
    Aug 8, 2019 at 9:54
  • line 24, you can search it :D
    – Jazuly
    Aug 8, 2019 at 9:55
  • @Jazuly yeah, you need a double escape for the \ since it's a php string. edited my answer
    – N69S
    Aug 8, 2019 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.