I know this question has been answered but my use case is slightly different. I am trying to setup a regex pattern to split a few strings into a list.
Input Strings:
1. "ABC-QWERT01"
2. "ABC-QWERT01DV"
3. "ABCQWER01"
Criteria of the string ABC - QWERT 01 DV 1 2 3 4 5
- The string will always start with three chars
- The dash is optional
- there will then be 3-10 chars
- Left padded 0-99 digits
- the suffix is 2 chars and is optional
Expected Output
1. ['ABC','-','QWERT','01']
1. ['ABC','-','QWERT','01', 'DV']
1. ['ABC','QWER','01','DV']
I have tried the following patterns a bunch of different ways but I am missing something. My thought was start at the beginning of the string, split after the first three chars or the dash, then split on the occurrence of two decimals.
Pattern 1: r"([ -?, \d{2}])+"
This works but doesn't break up the string by the first three chars if the dash is missing
Pattern 2: r"([^[a-z]{3}, -?, \d{2}])+"
This fails as a non-pattern match, nothing gets split
Pattern 3: r"([^[a-z]{3}|-?, \d{2}])+"
This fails as a non-pattern match, nothing gets split
Any tips or suggestions?
like
while its no regex, there are other options, including being able to restrict to only numeric chars, or single chars etc. Give that a go, and if you can't get that to work post a new question (after searching because there are a lot of existing questions on this sort of thing).