/.*?/.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.
通过使用*
代替eg +
您允许将空字符串作为非贪婪选项进行匹配。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.