I have some sample text as below:
MTG-2022039036 MTG
MTG-LR 3136 / 130 MTG
MTG-LR 201260 / 9046 ASSIGN
MTG-2021063349 MTG
My desired Results:
2022039036
3136 / 130
201260 / 9046
2021063349
My regex patterns work individually just fine example:
match1 = re.search(r'(\d+ \/ ?\d+)', ref)
num1 = match1.group(1) if match1 else None
# correctly returns 3136 / 130
match2 = re.search(r'(?:-?)(\d+)', ref)
num2 = match2.group(1) if match2 else None
# correctly returns 2021063349
But I want to combine them in one line like below to match either one or other pattern since only one case will occur in each string:
match = re.search(r'(?:-?)(\d+)|(\d+ \/ ?\d+)', ref)
num = match.group(1) if match else None
# This only returns 3136
I feel like I'm doing a very simple thing but no idea why now this doesn't work. I have used '|' for matching either or conditions in pandas str.extract() and had no problems there. Please advise.