0

The regular expression: "^\d{1,3}-\d{1,3}$" works for onetime pattern i.e. "400-900" but the regular expression with ? is not working for the repetition i.e. "^\d{1,3}-\d{1,3}$?" is not identifying the string "499-999,0-99".

Any suggestions, what the regular expression be?

Steelbird
  • 49
  • 6
  • The first answer on the "already answered" page will guide you in the right direction ... – hwnd Oct 20 '14 at 05:15

1 Answers1

1

Change your pattern like below to match also the strings which has repetation.

@"^\d{1,3}-\d{1,3}(?:,\d{1,3}-\d{1,3})?$"

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • the repetition would only be at the max once. i.e. "499-999,0-99" is not it could go up to and not more than that. Does that make any difference in using the above? – Steelbird Oct 20 '14 at 05:22
  • replace `*` with `?` , this turn the second non-capturing group as optional one. – Avinash Raj Oct 20 '14 at 05:23