简体   繁体   English

需要正则表达式将整数从数组中分离为逗号分隔

[英]Need regex to separate the integer from the array to comma separated

I am looking to have a regex for passing a value in the array to comma separated. 我正在寻找一个正则表达式,用于将数组中的值传递给逗号分隔。 Here is the regex I used for the fetching the value. 这是我用于获取值的正则表达式。

Regex: id="selectedAgency(.+?)" currently using this regex I am able to find the below value which is matching in id="selectedAgency[1]" 正则表达式:id =“ selectedAgency(。+?)”当前正在使用此正则表达式,我能够找到以下与id =“ selectedAgency [1]”匹配的值

Hence the outcome I receives is as follows: 因此,我收到的结果如下:

&selectedAgencies=[14],[12],[10],[9] &selectedAgencies = [14],[12],[10],[9]

However I would like to have the actual output as the below: 但是我想有如下实际输出:

&selectedAgencies= 14,12,10,9 &selectedAgencies = 14,12,10,9

not sure if this JavaScript version works for you but here it is. 不确定此JavaScript版本是否适用于您,但是确实如此。 Hopefully the regex and replace part should help. 希望正则表达式和替换部分应该有所帮助。

let str = "&selectedAgencies=[14],[12],[10],[9]";
let result = str.replace(/\[(\d+)\]/g, "$1");   //&selectedAgencies=14,12,10,9

在此处输入图片说明 To remove [] use different regex: 要删除[],请使用其他正则表达式:

 Regex : id="selectedAgency\[(\d+)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM