Home > Blockchain >  Regex to split alphanumeric string
Regex to split alphanumeric string

Time:04-14

How do i use regex to split the string if it's "Amazon2204231550PE" as ['Amazon','2204231550PE'] and "Amazon-P2204231550PE" to ['Amazon-P','2204231550PE'] in python.

CodePudding user response:

You could use re.findall as follows:

inp = "Amazon2204231550PE"
parts = re.findall(r'^[A-Z] |[0-9] .*$', inp, flags=re.I)
print(parts)  # ['Amazon', '2204231550PE']
  • Related