query-matches-and-captures function

Query matches and captures