use pattern matching to detect registers