How would I write a regex to take any input string and output only the letters?
input:
'This is a sentence. &)$&(@#1232&()$123!!ª•º–ª§∞•¶§¢• This is an example of the input string. '
output:
'thisisasentencethisisanexampleoftheinputstring'
You can remove all the non-letters like this:
var input = 'This is a sentence. &)$&(@#1232&()$123!!ª•º–ª§∞•¶§¢• This is an example of the input string. ';
var output = input.replace(/[^a-zA-Z]/g, "");
If you want the output to be all lowercase, then add .toLowerCase() onto the end like this:
var output = input.replace(/[^a-zA-Z]/g, "").toLowerCase();
By way of explanation, this regex matches all characters that are not a-z or A-Z. The g flag on the end of the regex tells it to replace all of them in the entire string (not just the first match it finds). And, the "" tells it to replace each match with an empty string (effectively removing all the match characters).
µa letter? How abouté?µis actually a lower case Greek letter that is also used as the Metric prefix for 10**-6.