I am running into an issue with preg_replace as I am not well-versed with regular expressions.
I am using this tool to test but the replace isn’t working as expected.
I have this input: http://example.com/test-menu/d/C101.
I am expecting this output: http://example.com/test-menu/d/101. I simply want to remove the letter C.
(the d can be any alphanumeric character)
I am attempting to use this regex.
Here is the php that the site is generating:
<?php
$ptn = "/\/test-menu\/(.)\/C/";
$str = "http://example.com/test-menu/d/C101";
$rpltxt = "/test-menu/$1";
echo preg_replace($ptn, $rpltxt, $str);
?>
I am not getting a match with my regular expression. What am I missing here?
Either:
(which uses a positive lookbehind with
(?<= ... ))Or:
(which captures the whole preceding string in the first submatch, all except the C)