Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String format checking?
#1
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.
Reply
#2
re module
regex101.com for test purposes and auto generated code
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Checking if a string contains all or any elements of a list k1llcod3 1 1,087 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  Set string in custom format korenron 4 1,079 Jan-16-2023, 07:46 PM
Last Post: mutantGOD
  Format String NewPi 2 937 Oct-10-2022, 05:50 PM
Last Post: NewPi
  TypeError: not enough arguments for format string MaartenRo 6 2,914 Jan-09-2022, 06:46 PM
Last Post: ibreeden
  string format challenge jfc 2 1,773 Oct-23-2021, 10:30 AM
Last Post: ibreeden
  Print first day of the week as string in date format MyerzzD 2 2,009 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  string.format() suddenly causing errors with google drive API zwitrader 0 1,753 Jun-28-2021, 11:38 PM
Last Post: zwitrader
  String to Date format SAF 2 2,442 Apr-06-2021, 02:09 PM
Last Post: snippsat
  checking a string for two instances of .. Skaperen 2 1,583 May-13-2020, 09:58 PM
Last Post: Skaperen
  MySQLdb._exceptions.ProgrammingError: not enough arguments for format string. farah97 0 3,326 Jan-22-2020, 03:49 AM
Last Post: farah97

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020