RSSAmplifier

Adam Johnson · Aug 15, 2026

Python: use re.prefixmatch() instead of re.match() from Python 3.15

0
Sign in to vote or save

This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.

Take this validation function: import re TRAIN_NUMBER_RE = re . compile ( r "\d {6} " ) # six digits def is_valid_train_number ( value : str ) -> bool : return bool ( TRAIN_NUMBER_RE . match ( value )) It looks reasonable, and it works for the intended cases: >>> is_valid_train_number ( "345071" ) True >>> is_valid_train_number ( "ABC123" ) False But, woah, it also accepts garbage suffixes: >>>…

Read on adamj.eu

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.