Can anyone please explain to me how this works in a python regular expression pattern? I tried to google but it didn't help:
a{1}
a{1, }
a{2, 3}
a{0, 1}
a{0, }
Can anyone please explain to me how this works in a python regular expression pattern? I tried to google but it didn't help:
a{1}
a{1, }
a{2, 3}
a{0, 1}
a{0, }
It's called "repetition qualifier" and it applies to preceding character (e.g. a
), set of characters (e.g. [0-9]
) or group (e.g. (foo)
) in regexp and with a single digit argument {n}
means exactly n
times. With two arguments {m, n}
it means at least m
and no more then n
times is expected to repeat in order to match. When the upper bound (n
,) is missing ({m,}
), it means at least m
and any greater number of repetitions. Omitting first argument ({,n}
) uses lower bound of 0
(no repetition). You can also check out the docs.
a{1}
: exactly one a
(same as just a
)a{1, }
: one or more occurrences of a
(a+
)a{2, 3}
: two or three occurrences of a
a{0, 1}
: one or none occurrence of a
(a?
)a{0, }
: zero or more (any number of) occurrence of a
(a*
)