-1

I have html string like that for example

<td align="left" nowrap="nowrap">John 23</td>

I want to find "John 23" between '<td align="left" nowrap="nowrap">' and '</td>'

I want to find with Regular Expressions in python

How can I do it?

Murad
  • 3
  • 4

1 Answers1

2

Use BeautifulSoup to parse HTML. Regex is the wrong tool; it works fine for this example but wouldn't scale well to a full document.

>>> from bs4 import BeautifulSoup
>>> html = '<td align="left" nowrap="nowrap">John 23</td>'
>>> BeautifulSoup(html).find("td").text
'John 23'
ggorlen
  • 44,755
  • 7
  • 76
  • 106