javascript在空格或数组引号上拆分字符串 [英] javascript split string on space or on quotes to array
本文介绍了javascript在空格或数组引号上拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var str = 'single words "fixed string of words"';
var astr = str.split(" "); // need fix
我希望数组如下:单个,单词,固定字符串。
i want the array to be like: single, words, fixed string of words.
推荐答案
str.match(/\w+|"[^"]+"/g)
//single, words, "fixed string of words"
这篇关于javascript在空格或数组引号上拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文