I was wondering If I could get a regular expression which will match a string that only has alphabetic characters, and that alone.
Share
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 may use any of these 2 variants:
to match an input string of ASCII alphabets.
[A-Za-z]will match all the alphabets (both lowercase and uppercase).^and$will make sure that nothing but these alphabets will be matched.Code:
Output:
Test case is for OP’s comment that he wants to match only if there are 1 or more alphabets present in the input. As you can see in the test case that matches failed because there was
^in the input stringabcAbc^Xyz.Note: Please note that the above answer only matches ASCII alphabets and doesn’t match Unicode characters. If you want to match Unicode letters then use:
Here,
\p{L}matches any kind of letter from any language