[Solved] (?:\d[ -]*?){13,16} – confused with the priority that is given in matching the pattern to the given regex [duplicate]


It captures 13-16 digits, each followed by zero or more spaces or dashes (the [ -]*?). In other words, the {13,16} applies to the entire group (?:\d[ -]*?). So, it could capture, for example, 1--2-3--4-5-6 7-----8-9-0-1-2-3-4-5-6-. In your sample case, it captures these 16 chunks:

  • 4
  • 5
  • 6
  • 4-
  • 1
  • 2
  • 3
  • 4-
  • 4
  • 3
  • 2
  • 5-
  • 2
  • 1
  • 4
  • 6

solved (?:\d[ -]*?){13,16} – confused with the priority that is given in matching the pattern to the given regex [duplicate]