RegEx - Keep only letters and digits

Advanced Renamer forum
#1 : 18/01-22 07:31
MaxEnrik
Posts: 12
name = 'AZ az 09!@#$%^&*()_+';
clean = /[^\pL\d]+/g;
result = name.replace(clean, '');
return result

Example:
'AZ az 09!@#$%^&*()_+'

Expect:
'AZ az 09'

But:
09
#2 : 18/01-22 10:03
David Lee
Posts: 1125
This appears to be a limitation of the JavaScript regex implementation, since the regex [^\pL\d ] works perfectly in other replacement methods.

However \pL will match any Unicode letter from any language - not just Latin (English) script so it may not do exactly what you want anyway.

Try the regex /[^a-z\d ]/gi
or /[^A-Za-z\d ]/g

#3 : 18/01-22 21:02
MaxEnrik
Posts: 12
Reply to #2:
Thank you a lot!