-2

I'm confused why this pattern captures 4564-1234-4325-2146, even though it has 19 digits including '-' The above pattern only captures 4564-1234435-2146-8 leaves the last hyphen and the digit 8

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
user
  • 13
  • 1

1 Answers1

1

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
elixenide
  • 44,308
  • 16
  • 74
  • 100