Saturday, 24 August 2013

Match last occurence with regex

Match last occurence with regex

I would like to match last occurence of a pattern using regex.
I have some text structured this way:
Pellentesque habitant morbi tristique senectus et netus et
lesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae
ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam
egestas <br>semper<br>tizi ouzou<br>Tizi Ouzou<br>
I want to match the last text between two <br> in my case <br>Tizi
Ouzou<br>, ideally the Tizi Ouzou string
Note that there is some white spaces after the last <br>
I've tried this:
<br>.*<br>\s*$
but it selects everything starting from the first <br> to the last.
NB: I'm on python, and I'm using pythex to test my regex

No comments:

Post a Comment