Capturing regular expression in Python
-
05-07-2021 - |
Domanda
I would like to use the regular expressions in Python to get everything that is after a </html>
tag, an put it in a string. So I tried to understand how to do it in Python but I was not able to make it work. Can anyone explain me how to do this ridiculous simple task ?
Soluzione
m = re.match(".*<\html>(.*)",my_html_text_string)
print m.groups()
or even better
print my_html_string.split("</html>")[-1]
Altri suggerimenti
You can do this without a regular expression:
text[text.find('</html>')+7:]
import re
text = 'foo</html>bar'
m = re.search('</html>(.*)', text)
print m.group(1)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow