0

I have written the following pattern to match an empty paragraph at the end of HTML:

https://regex101.com/r/6TNgUV/1

But when I try the following Python code, the result is None

html_desc = '</span><p></p><p></p>'
res = re.match('(<p>){1}(\s)*(<br>|<br\/>){0,9}(\s)*(<\/p>){1}(\s)*$', html_desc) 
#  returns None

I am not able to understand the issue.

Ken Lee
  • 6,985
  • 3
  • 10
  • 29
Hooman Bahreini
  • 14,480
  • 11
  • 70
  • 137
  • 1
    You need `re.search`, since `re.match` anchors the match to the start. See [this](https://stackoverflow.com/questions/180986/what-is-the-difference-between-re-search-and-re-match) – costaparas Jan 03 '21 at 01:59

1 Answers1

0

re.match matches starting with the first character, and since your HTML string starts with a tag, it returns the default case, None, maybe use re.search() instead of re.match()

Nour
  • 210
  • 1
  • 10