HELP with preg_replace. Easy one for expert

Hi,

Can’t seem to get my head around this one: Every time I use preg_replace(), it’s returning the string with the first letter replaced, but nothing else.

Here’s an example:


$sentence = "I'm trying to filter a @($* last name like Smith-Klein.";
echo preg_replace("/^[a-zA-Z \\'\\-\\.]/", "", $sentence );

I think this should return:

I’m trying to filter a last name like Smith-Klein.

Instead, it’s returning:

'm trying to filter a @($* last name like Smith-Klein.

Any idea where I’m going wrong?

Thanks,

Pavel

Mystery solved…

/[^a-zA-Z \'\-\.]/

NOT

/[1]/

Knew it’d be easy.


  1. a-zA-Z \'\-\. ↩︎