使用javascript分割字符串 [英] split a string using javascript
本文介绍了使用javascript分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像; a; b; c ;; e这样的字符串。请注意,在 e
之前有一个额外的分号。我希望将字符串拆分为 a
, b
, c;
, e
。但它分为 a
, b
, c
, ; e
。
I have a string like ";a;b;c;;e". Notice that there is an extra semicolon before e
. I want the string to be split in a
, b
, c;
, e
. But it gets split like a
, b
, c
, ;e
.
我的代码是
var new_arr = str.split(';');
我可以在这做什么来获得我想要的结果?
What can I do over here to get the result I want?
问候
推荐答案
使用Regexp负向前瞻:
Use a Regexp negative lookahead:
";a;b;c;;e".split(/;(?!;)/)
这篇关于使用javascript分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文