# 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']
Updated on 16-Dec-2019 09:01:20