문제

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

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

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top