Is the package threadsafe?
Yes, by design. Once a RE object is compiled, it is never modified. Runtime data is attached to REMatch objects, which are created for each thread executing one of the match methods. Subexpression Indices I have a regular expression that looks like “(Hello)World|(Foo)Bar”. When I try to match the text “HelloWorldFooBar”, the first match returns “HelloWorld” and its first subexpression is “Hello”, both of which are correct. For the second match I get “FooBar”, but the first subexpression is empty. What gives? The behavior is correct. The subexpressions are numbered according to their position in the entire regular expression. Therefore the subexpression that matches “Foo” in the second match is subexpression number two.