[英]spliting string except in curly brackets
I'm trying to split a string on ","
but I don't want to split if ","
is in "{}"
. 我正在尝试在
","
上拆分字符串","
但是如果","
在"{}"
","
我不想拆分。 There's no nested braces. 没有嵌套的括号。
here is the string I want to split : 这是我想分割的字符串:
EmbiBISupplierKPIResult_EditArea00001,EmbiBISupplierKPISearch,partyId=E10021&economicAreaPartyIds={DPP_20246, DPP_14726}&economicId={DPP_20246, DPP_14726}&requestedDateSearchType=ACTUAL_WEEK
EmbiBISupplierKPIResult_EditArea00001,EmbiBISupplierKPISearch,partyId = E10021&economicAreaPartyIds = {DPP_20246,DPP_14726}&economicId = {DPP_20246,DPP_14726}&requestedDateSearchType = ACTUAL_WEEK
Here is the result I expect : 这是我期望的结果:
EmbiBISupplierKPIResult_EditArea00001
EmbiBISupplierKPISearch
partyId=E10021&economicAreaPartyIds={DPP_20246, DPP_14726}&economicId={DPP_20246, DPP_14726}&requestedDateSearchType=ACTUAL_WEEK
Is there a regex to do this ? 有正则表达式可以做到这一点吗?
You can use match
and be explicit about the optional matching of parts between braces: 您可以使用
match
并明确显示括号之间各部分的可选匹配:
var parts = s.match(/(\{[^{}]*\}|[^,{}]+)+/g)
var s = 'EmbiBISupplierKPIResult_EditArea00001,EmbiBISupplierKPISearch,partyId=E10021&economicAreaPartyIds={DPP_20246, DPP_14726}&economicId={DPP_20246, DPP_14726}&requestedDateSearchType=ACTUAL_WEEK'; var parts = s.match(/(\\{[^{}]*\\}|[^,{}]+)+/g) document.querySelector('pre').innerHTML = JSON.stringify(parts,null,'\\t');
<pre id=result></pre>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.