regular expression 3 quantifiers
by webproger on 2020-03-22
<JavaScript>
*       Specifies zero or more matches. Same as {0,}.
+       Specifies one or more matches. Same as {1,}.
?       Specifies zero or one matches. Same as {0,1}.
{n}     Specifies exactly n matches.
{n,}    Specifies at least n matches.
{n,m}   Specifies at least n, but no more than m, matches.
*?      Specifies the first match that consumes as few repeats as possible (lazy *).
+?      Specifies as few repeats as possible, but at least one (lazy +).
??      Specifies zero repeats if possible, or one (lazy ?).
{n}?    Equivalent to {n} (lazy {n}).
{n,}?   Specifies as few repeats as possible, but at least n (lazy {n,}).
{n,m}?  Specifies as few repeats as possible between n and m (lazy {n,m}).

*lazy quantifier: If ? is used immediately after any of the quantifiers *, +, ?, or {}, it makes the quantifier non-greedy (matching the minimum number of times), as opposed to the default, which is greedy (matching the maximum number of times).
var re = /a{1,3}(\w)/ ; var ary = re.exec('aaab'); window.alert(ary[1]); => "b"
var re = /a{1,3}?(\w)/; var ary = re.exec('aaab'); window.alert(ary[1]); => "a"