Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在正则表达式\d+中匹配所有数字,但它与数字不匹配,1k或者1.4k我应该如何制作一个正则表达式来计算这些数字?
\d+
1k
1.4k
我想要的是:
有效的:
无效的:
我是正则表达式的新手,我不知道如何开始
你可以用这个
\d+(\.\d+)?K
(\.\d+)?
.
?
k
K
演示
你只需要添加K到你的正则表达式
/(\d|.\d)+K?/g
我建议你使用像regexr.com这样的工具