RegEx - Keep only letters and digits

Advanced Renamer forum
#1 : 18/01-22 07:31
MaxEnrik
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


18/01-22 07:31
#2 : 18/01-22 10:03
David Lee
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



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


18/01-22 21:02