0
/.*?/.exec("abc");//output [""]

I think .*? is non-greedy and it should return a

looping
  • 1,141
  • 3
  • 11
  • 20

2 Answers2

6

Well that is expected since .* means 0 or more and by putting ? you make it non-greedy hence it match an empty string.

If you want to match a then you should use:

 /.+?/.exec("abc");

DIfference is + instead of * which means match 1 or more characters using non-greedy quantifier.

anubhava
  • 761,203
  • 64
  • 569
  • 643
0

By using * instead of e.g. + you allowed for matching empty string as a non-greedy option.

guessimtoolate
  • 8,372
  • 2
  • 18
  • 26