i want to capture only the first match through the expression
<p>.*?</p>
i have tried <p>.*?</p>{1} but it is not working it returns all the p tags which are in the html document, please help
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.
It looks like you are using a method which returns every match in the string given a regex, that being the case you need to anchor the regex to the beggining of the string so it doesn’t return every match, but only the first one:
Use parentheses to capture what you want to capture.
PS: Here goes the standard ‘avoid using regex to parse HTML, use a proper HTML parser’ advice. This simple regex will fail for nested
<p>sections (which I don’t recall if are valid in HTML, but still you can probably get them even if they aren’t).