Kết hợp anchor \b (word boundary), \S (non-whitespace) để khớp từ bắt đầu bằng 'T' và kết thúc bằng 'y'.
Ví dụ
import re result = re.findall(r'\bT\S+y\b', 'TestCountry Hello') print(result) # ['TestCountry']
Giải thích pattern \bT\S+y\b
\b— word boundary (đầu từ).T— ký tự 'T' literal.\S+— 1+ ký tự non-whitespace (phần giữa).y— ký tự 'y' literal.\b— word boundary (cuối từ).
Lưu ý: Pattern này yêu cầu từ không chứa whitespace. Để khớp chuỗi có space, dùng ^T.*y$ với flag re.DOTALL.