In this statement, taken from the Pagerank source code:
Pattern.compile("\\[.+?\\]");
What does the pattern mean? I have tried studying it, it says 2 slashes mean a single slash, but what are the .+??
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.
This string literal:
means this string:
So this expression:
means this regex:
which means “a literal
[, followed by one or more characters — preferably as few as possible — followed by]“. (.means “any character other than newline”;+?means “one or more of what I just said, and preferably as few as possible”.) So overall, the regex matches[____], where____can be anything that doesn’t contain a newline, as long as it’s at least one character long; and where____won’t (normally) contain a]except possibly as the very first character.For more information about
Patternand regexes in Java, see the documentation for thePatternclass.