I want to capture numbers and number ranges from a list: ["op.15", "Op.16-17", "Op16,17,18"]
match = re.compile(r"\d+[-]?\d+").findall(text)
Gets the correct result
op.15 ['15']
Op.16-17 ['16-17']
Op16,17,18 ['16', '17', '18']
but this doesn't work:
match = re.compile(r"\d+(-)?\d+").findall(text)
op.15 ['']
Op.16-17 ['-']
Op16,17,18 ['', '', '']
What's the issue here? I want to add in alternative values to -
, such as "to"
i.e. -|to
which doesn't work with []
.