preg_replace question

Hi Guys…

I need some regex code that will only allow the following characters:

  • letters
  • numbers
  • spaces
  • carriage returns
  • full stop (.)
  • comma (,)
  • dash (-)

Everything else will get removed…Any idea how to do this?

What pattern have you got so far?

$plaintext = preg_replace(“/[^a-z0-9_-]+/i”, “”, $plaintext);

This is what I am trying to do, but what would be the correct syntax:


$plaintext = preg_replace("/[^a-z0-9 _.:;,-][/\\r\
/]+/i", "", $plaintext);


$plaintext = preg_replace("/[^a-z0-9 _\\.:;,\\-\\r\
]/i", "", $plaintext);

Perfect, I think that works - thank you! :slight_smile: