Python – Using regex to find multiple matches and print them out [duplicate]

Do not use regular expressions to parse HTML.

But if you ever need to find all regexp matches in a string, use the findall function.

import re
line="bla bla bla<form>Form 1</form> some text...<form>Form 2</form> more text?"
matches = re.findall('<form>(.*?)</form>', line, re.DOTALL)
print(matches)

# Output: ['Form 1', 'Form 2']

Leave a Comment