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.
我在 JS 中有一个数字,例如2,5或2.5
2,5
2.5
我想使用多重拆分,例如
'2.5'.split(/,|./)
但它给了我错误的输出,为什么?:
["", "", "", ""]
/,|./是不正确的正则表达式。它应该在字符类中/[,.]/或被转义/,|\./
/,|./
/[,.]/
/,|\./
这有效:'2.5'.split(/[.,]/)
'2.5'.split(/[.,]/)
逃脱. 正则表达式元字符
'2.5'.split(/,|\./)