Is there an easier regex to filter non-letters (like %¤#£?| etc.) from a string, where I want to accept all letters (also special ones like æøåôöñ etc.). Do I have to explicitly include every special letter in the regex or is there a smarter way
$filteredString = preg_replace('/[^a-zæøåÆØÅöôÖÔ 0-9]/i', '', $orgString);
ps. As you see, I'd like to accept whitespaces as the only non-letter char
pps. Also the caseinsensitive "i" does not seem to apply with special letters
/[^\w\s\pL]/u
See php regex. These are all word characters, whitespace and Unicode letters. The trailing u
indicates Unicode handling.
You can use \w
for word character (includes underscore as well), also better to use u
modifier for unicode characters:
/[^\w\sæøåÆØÅöôÖÔ]/iu