How can I match the start and end in Python's regex?

PythonServer Side ProgrammingProgramming

We have the given string ‘TestCountry Hello’. To match and print that part of the string which starts and ends with characters ‘T’ and ‘y’ respectively we use the findall method of module re , word boundary anchor \b and non-whitespace character \S in the regex:

Example

import re
result = re.findall(r"\bT\S+y\b", 'TestCountry Hello')
print result

Output

to get output as

['TestCountry']
raja
Published on 28-Dec-2017 12:54:56
Advertisements