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'
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can remove all the non-letters like this:
If you want the output to be all lowercase, then add
.toLowerCase()onto the end like this:By way of explanation, this regex matches all characters that are not
a-zorA-Z. Thegflag 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).