Extract shared pattern matching module