var mystring = 'Hello test1 "test2 but one word" test3 test4 ';
var mystring_ar= mystring.split(/\s+/);
okay I have this /\s+/
expression so I can seperate from spaces but my problem is I want to seperate from spaces and regular expression should not seperate word if words surrounded by "
, like "test2 but one word"
For example below:
'Hello test1 "test2 but one word" test3 test4 '.split(regex)
=> ['Hello','test1','test2 but one word','test3','test4']
is that possible?
Edited
I have found half solution but not completed below code seperate correctly but only works for words for example if string is a/b/as d
, it will not seperate it to a/b/as and d
,it will seperate it to a,b,as,d
keywords = keywords.match(/\w+|"[^"]+"/g);
But I think solution should be with split
.It should work like seperate from whitespaces
and don't seperate inside of ""