I am trying to find a regex that will pull out information between two dashes, but after a dash has already existed.
I will list a few examples:
a = BRAND NAME - 34953 Some Information, PPF - 00003 - (3.355pz.) 300%
b = 893535 - MX LMESJFG - 01001 - ST2 | ls.33.dg - OK
c = 4539883 - AB05 - AG03J238B - | D.87.yes.4/3 - OK
What I want to pull out:
a = 00003
b = 01001
c = AG03J238B
I would greatly appreciate any help.
CodePudding user response:
We can stick to the base string functions here and use split()
and strip()
:
a = "BRAND NAME - 34953 Some Information, PPF - 00003 - (3.355pz.) 300%"
match = a.split("-")[2].strip()
print(match) # 00003
CodePudding user response:
Little late to the party, but the following python regular expression should find all occurrences for each line of file (assuming your using python language). Hope this works for you. Not limited to string splits failures I don't think
import re
match = re.findall(r"(?=(-\s\w \s-))", c)
print(match)
the (?=()) allows you to find overlapping issues, look up in the documents for look aheads and look behinds. Good luck.