This is what I came up so far
var split_string = string_a.split(/(?:"|",")/);
however for
var string_a ='"ldfssdf","mom , ddd"';
its not giving the right result in the array what i basically want is this
string_a = ["ldfssdf", "mom, ddd"];
This is what I came up so far
var split_string = string_a.split(/(?:"|",")/);
however for
var string_a ='"ldfssdf","mom , ddd"';
its not giving the right result in the array what i basically want is this
string_a = ["ldfssdf", "mom, ddd"];
,(?=(?:[^"]*"[^"]*")*[^"]*$)
Split by this.See demo.
https://regex101.com/r/fA6wE2/11
NODE EXPLANATION
--------------------------------------------------------------------------------
, ','
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
--------------------------------------------------------------------------------
[^"]* any character except: '"' (0 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
" '"'
--------------------------------------------------------------------------------
[^"]* any character except: '"' (0 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
" '"'
--------------------------------------------------------------------------------
)* end of grouping
--------------------------------------------------------------------------------
[^"]* any character except: '"' (0 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
$ before an optional \n, and the end of
the string
--------------------------------------------------------------------------------
) end of look-ahead
Here is what you want to do.
Check this link out: http://jsfiddle.net/duongtuanluc/q8z7fkgx/
Check this link out: http://jsfiddle.net/duongtuanluc/q8z7fkgx/1/ (If contains empty value "")
var string_a ='"ldfssdf","mom , ddd"';
var rgx = /(\"[\s\S]+?\")/g;
var arr = string_a.match(rgx);
console.log(arr);
