String input = "2012 AL REG TEXT 300535(NS)";
String regex = "^((\\d{4})\\s+)?((\\S+)\\s+(.+?)\\s+)\\s+((\\S+)(\\s+\\(.*?\\)))$";
I want to capture 2012 in a group, “AL REG TEXT” in another group, and “300535(NS)” in another group.
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.
The error is that you have an extra
\\s+right before the expected parantheses and, as @cmonkey points out, an extra\\s+in the middle. Remove these and it works. Also, to only get the groups you mention above, add?:to the ones you don’t want to capture:prints