RegEx - Keep only letters and digits
name = 'AZ az 09!@#$%^&*()_+';
clean = /[^\pL\d]+/g;
result = name.replace(clean, '');
return result
Example:
'AZ az 09!@#$%^&*()_+'
Expect:
'AZ az 09'
But:
09
clean = /[^\pL\d]+/g;
result = name.replace(clean, '');
return result
Example:
'AZ az 09!@#$%^&*()_+'
Expect:
'AZ az 09'
But:
09
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
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
Reply to #2:
Thank you a lot!
Thank you a lot!