![]() |
VOOZH | about |
Given a string, the task is to check whether it ends with an alphanumeric character (A–Z, a–z, 0–9). For example:
Input: hello123 -> Accept
Input: hello@ -> Discard
Let's explore different regex-based methods to perform this check in Python.
fullmatch() ensures the entire string must follow the regex pattern. We allow any characters before the end and enforce that the last character must be alphanumeric.
Accept
Explanation:
match() starts checking from the beginning, so adding start (^) and end ($) anchors forces a full-string match.
Accept
Explanation:
search() scans the whole string, but since the regex ends with $, it only matches if the very last character is alphanumeric.
Accept
Explanation:
findall() returns all matches. Here it extracts only the last character if it is alphanumeric.
Accept
Explanation: