3

I know that in regex one can specify the desired number of matches via the curly braces as {min,max}

I was going through this article: http://msdn.microsoft.com/en-us/library/ms537509%28v=vs.85%29.aspx

and coudn,t understand what is meant by {1,} or {0,} etc.

user1107888
  • 1,481
  • 5
  • 34
  • 55
  • 2
    These are the same as `+` and `*`. Whoever wrote `[0-9]{1,}[\.0-9]{0,}` had no idea what they were doing - it is much better as `\d+(?:\.\d+)?` (unless `MSIE 2.` is valid). – Kobi Aug 09 '12 at 08:30
  • Actually, My pattern is ignoring sub versions, so make that `\d+(?:\.\d+)*`. Easy fix `:)` – Kobi Aug 09 '12 at 08:40

3 Answers3

5

this is infinity in regex

{0,} = * is mean {0,infinity}

{1,} = + is mean {1,infinity}

burning_LEGION
  • 13,246
  • 8
  • 40
  • 52
2

it means no upper bound, but a lower bound. eg

See : http://regexr.com?31piu

\d{3,}

will match all the sequences of 1 where there are more than 3 continous 1s, be it four 1s, or ten 1s

1111----1111111111----11--1----11111111111111111111--111

Same way,

{1,} would mean 1 or more instances i.e. a + wildcard

{0,} would mean 0 or more instances i.e. a * wildcard

DhruvPathak
  • 42,059
  • 16
  • 116
  • 175
0

{n,} where n >= 0 : "Repeats the previous item at least n times. Greedy, so as many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is matched only n times."

Refer to this regex reference, there's a lot of handy examples in it:

army
  • 545
  • 5
  • 16