I am trying to read someone else’s code and I came across this piece of regex. Can anyone tell whats the author trying to do ?
if(str.matches("^\\s*$") && !str.matches("^\\s*#.*")) {
// do something
}
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 first pattern looks for an empty line – a line containing only white space (spaces, tabs, etc).
The second pattern looks for lines starting with white space followed by a
#(hash), and ignores them.It’s odd; anything that matches the first regex won’t match the second, so the second test is pointless. To make sense, the test should probably be:
Or: