<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>
I know this regex expression is used to retrieve the value of src. Can anyone teach me how i should interpret this expression? stucked at it.
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.
Explaining:
<imgmatches exactly the string"<img"[^>]+matches multiple times of everything but>, so the tag will not be closedsrcmatches exactly the string “src”\\s*matches any number of whitespace characters=matches exactly the string “=”\\s*matches any number of whitespace characters['\"]matches the two quotes. The double quote is escaped, because otherwise it will terminate the string of the regex([^'\"]+)mathches multiple times everything but quotes. The contents are wrapped in brackets, so that they are declared as group and can be retrieved later['\"]matches the two quotes. The double quote is escaped, because otherwise it will terminate the string of the regex[^>]*matches the remaining non">"characters>matches exactly the string">", the closing bracket of the tag.I would not agree this expression is a crap, just a bit complex.
EDIT Here you go some examplary code:
The output is:
So
matcher.group(1)returns what you want. experiment a bit with this code.