Computer >> Computer tutorials >  >> Programming >> Python

How to match at the end of string in python using Regular Expression?


The following code matches the word 'stadium' at the end of the string ' cheer leaders at the football stadium'

$-matches the end of the string

Example

import re
s = 'cheer leaders at the football stadium'
result = re.search(r'\w+$', s)
print result.group()

Output

This gives the output

stadium