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:
import re result = re.findall(r"\bT\S+y\b", 'TestCountry Hello') print result
to get output as
['TestCountry']