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

PythonServer Side ProgrammingProgramming

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
raja
Published on 02-Jan-2018 10:57:17
Advertisements