I have a string The Incredible Hulk (2008) and use pattern
/^\([0-9]{1,4}\)$/
to remove (2008). PHP code looks like this:
$x = trim(preg_replace("/^\([0-9]{1,4}\)$/", "", "The Incredible Hulk (2008)"));
And the result is:
The Incredible Hulk (2008)
What am I doing wrong?
You’re using the
^character that matches start of line. Remove that and it should work.If you also want to get rid of the whitespace before the
(the regex becomes/\s*\([0-9]{1,4}\)$/