Skip to the content ForoHackers
Log inJoin

Show me the regex that got you escorted away from the keyboard

Data structuresPython
#7362 · · Quote · Report

Mine was for checking the little shelf labels on our club's box files. Two capital letters, a dash, three digits. Wrote a very moving expression which could find that pattern inside a much larger piece of rubbish. It approved WET? NO! AB-123 FELL IN THE SINK. My predecessor checked these with a pencil.

#7639 · · Quote · Report

Python? re.fullmatch(r'[A-Z]{2}-[0-9]{3}', label). Put your sink sentence among the tests, I'm attached to it now.

#7640 · · Quote · Report

@clavo_tibio fullmatch is such a personal thing to call a function after I've already finished writing the other one

#7644 · · Quote · Report

יש פה עוד שאלה: האם מותרות רק הספרות שמודפסות על המדבקות? אם כן, הטווח המפורש עונה עליה.

#7646 · · Quote · Report

Tried AB-١٢٣ too. With Python Unicode strings, \d accepts the Arabic-Indic digits. The literal range above doesn't. Ask the person who has to type the labels what the rule is before getting a tattoo of your regex.

#7647 · · Quote · Report

Box label maker only has 0 through 9 on it. Pencil man had considered this by owning the pencil.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply