Use a common function for matching query and fragment