I have written 2 REs to match several string sequences in a String. for e.g. lets assume the two regular expressions are RE1
, RE2
. The strings can be i
Using |
in your regex and re.findall() is probably the way to go, here is an example:
>>> pattern = re.compile(r"(\d{1,3}[a-zA-Z]?/\d{1,3}[a-zA-Z]?|\babc\b)")
>>> pattern.findall("*some string* 100/64h *some string* 120h/90 *some string* abc 200/100 abc *some string* 100h/100f")
['100/64h', '120h/90', 'abc', '200/100', 'abc', '100h/100f']
If it is valid for your patterns to overlap then this won't work.