![](/img/trans.png)
[英]JavaScript foreach an array and split them with commas and last one's comma with "and"
[英]How to use split to split with commas except the comma that has one preceding character and 6 succeeding characters
所以我有一个这样的字符串transaction_20,190.68,huwaei,2019/02 / 14,1,256.32,AUS
我希望在逗号后分割字符串,但我不想分割此逗号1,256.32,因为这是价格,我注意到我不想分割的逗号始终具有1个前字符和6个后继字符。 有人可以帮我解决如何在javascript中做到这一点。 任何帮助将不胜感激。
在逗号上分割时,负前瞻3位数字,后跟一个单词边界:
const input = 'transaction_20,190.68,huwaei,2019/02/14,1,256.32,AUS'; const splitted = input.split(/,(?!\\d{3}\\b)/); console.log(splitted);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.