Quick question.
What’s the code for Java regex that matches a string that has {1,2,3,4,5,6,7,8,9,T,J,Q,K} on the 1st char and {S,D,C,H} on the second. How can I do that?
Thanks.
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.
Very simple:
Note that using
^and$means that the string contains only two chars and respect the rules you need.As Jonathon Reinhart points out, maybe my one-line explanation is not enough. Obviously you should study in deep what that sign means. Anyway a good start point is his description:
^means “at start of string”[1-9TJQK]means “any one character between 1 and 9 (inclusive) or T or J or Q or K[SDCH]Same logic as before$means “at end of string”