I am using this regexp - [^\s\da-zA-ZåäöÅÄÖ]+$
to filter out anything but A-Z, 0-9 plus the Swedish characters ÅÄÖ
. It works as expected as long as the string isn't ending with whitespace and I am a bit confused on what I need correct to make it accept strings even if they end with whitespace. The \s
is there but is apparently not enough.
What is wrong in my regexp?
"something #¤%&/()=?".replace(/[^\s\da-zA-ZåäöÅÄÖ]+$/, '') # => a string
"something ending with whitespace #¤%&/()=? ".replace(/[^\s\da-zA-ZåäöÅÄÖ]+$/, '')# => a string ending with space #¤%&/()=?