I need to add the regular expression in java to test the string whether it contains only alphanumeric( with or without “-“).
Ex:
ADB123
ABC-D1
12ABCD
A-BCD1
etc.
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 try
prints
The regex
[-\\p{Alnum}]+means[ ]+means one or more of any of the characters.-at the start means-not and not something else.\\in a String literal turns into just\as it is an escape character.\p{Alnum}is a predefined list of alpha and numeric characters.See the documentation for Pattern for more details.