javascript - JS regex exclude matches inside quotes -
this code:
var value = 'one.two[0]["three.four"]'; console.log(value.split(/(?:\.)|(?=\[")/));
produces following array:
0: 1 1: two[0] 2: ["three 3: four"]
how can modify exclude dots inside quotes? i'd output:
0: 1 1: two[0] 2: ["three.four"]
you can add negative lookahead after .
add "exclude dots inside quotes" logic. ignore opening quote , lookahead see if we're inside quoted string. (which we're assuming here not contain weirdness escaped quotes \"
)
var value = 'one.two[0]["three.four.five"]'; console.log(value.split(/\.(?![\w.]*")|(?=\[")/));
Comments
Post a Comment