php - Regex: Strip non alpha numeric or punctuation -


How do I use PHP to extract alpha, numeric, space or all non-paranoid characters?

I have tried the following, but left this punctuation mark.

  preg_replace ("/ [^ a-zA-Z0- 9 \ s] /", "", $ str);  

  preg_replace ("/ [^ a-zA-Z0-9 \ S \ p {P}] / "," ", $ str);  

Example:

  php> Echo preg_replace ("/ [^ a-zA-Z0- 9 \ s \ p {P}] /", "", "⟺f✆oo☃. Ba⟗r!"); Foo times!  

\ p {P} matches all Unicode punctuation (see Unicode). If you want to allow only specific punctuation marks, then add them to the denoted square class. Example:

  preg_replace ("/ [^ a-zA-Z0-9 \?.] /", "", $ Str);  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -