Anchor $ khớp vị trí cuối chuỗi (trước newline cuối nếu có, hoặc cuối tuyệt đối).
Ví dụ
import re s = 'cheer leaders at the football stadium' result = re.search(r'\w+$', s) print(result.group()) # stadium
Kết quả
stadium
Giải thích: \w+$ khớp một từ (\w+) ngay trước cuối chuỗi.
Lưu ý: Với flag re.MULTILINE (re.M), $ khớp cuối mỗi dòng.