Question: what is the difference between test () and exec () methods?
Answer: Difference between test () and exec () methods in Javascript Test tests for matches and returns booleans while exec captures groups and matches the regex to the input. If you only need to test an input string to match a regular expression, RegExp.