Python Forum

Full Version: String format checking?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What's the most elegant solution for checking a string format where I need to match a single alpha then 3 numerics?

examples:
p130 is good.
130p is bad.
pg130 is bad.
p13 is bad.
p3p is bad.

So in this case I need 1 alpha and 3 numerics. Although a solution that was easily configurable would be good.

I could do this with a load of 'if in' checks, but there must be a better answer.

Many thanks.
re module
regex101.com for test purposes and auto generated code