2

I've been searching for a long time but didn't find an answer for my question, can tell me what the meaning of

(?:[-\w\d{1-3}]+\.)+

and not

(?:[-\w\d{1,3}]+\.)+

I don't understand the {1-3} part and can't find anywhere what it's mean. Thank you

  • 1
    Sorry to be blunt, but that pattern is complete garbage and whoever wrote it had no idea what they were doing. See this: https://www.debuggex.com/r/Fh0mC-RVZ0J2WRbe – Kobi Jan 22 '15 at 10:23
  • The duplicate closing reason is incorrect, but yes, this regex doesn't make sense. The character group`[]` includes a dash, a word character, a digit (which generally is already a word character), an opening brace, digits 1 to 3 (inclusive), and a closing brace. So all the extra digits references are redundant. –  Jan 22 '15 at 10:30
  • `\d` matches a digit and this `{1-3}` matches literal `{1-3}` – Avinash Raj Jan 22 '15 at 10:36
  • Thank you for your answer – Christopher Vuong Jan 22 '15 at 11:15

1 Answers1

6

Everything between [] are characters to be matched. So it matches each of those characters:

  • - the literal character -
  • \w match any word character [a-zA-Z0-9_]
  • \d match a digit [0-9]
  • { the literal character {
  • 1-3 a single character in the range between 1 and 3
  • } the literal character }

the 1-3 makes no sense there, as well as the \d. Both are included in \w Even what you would say that is correct {1,3} inside the [] makes no sense.

OriolBG
  • 1,904
  • 1
  • 15
  • 21