Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 不适用于重复数对(JS)的RegExp_Javascript_Regex_Replace - Fatal编程技术网

Javascript 不适用于重复数对(JS)的RegExp

Javascript 不适用于重复数对(JS)的RegExp,javascript,regex,replace,Javascript,Regex,Replace,我想通过这个RegExp遍历字符串的内容,并简单地将数对升序为1 范例 发件人: text“1”text“1” 文本“1”文本“1” 文本“1”文本“1” ... 致: text“1”text“1” 文本“2”文本“2” 文本“3”文本“3” 直到第n个号码。。。 上面的代码片段仅表示需要更换的零件, 其中“文本”和标记可以是任何内容,因为我无法控制html输入 查看当前脚本的外观: 如果我正确理解了您的意思,这将有助于: 临时字符串: id="1" some text "1", id=

我想通过这个RegExp遍历字符串的内容,并简单地将数对升序为1

范例

发件人:

text“1”text“1”
文本“1”文本“1”
文本“1”文本“1”
...
致:

text“1”text“1”
文本“2”文本“2”
文本“3”文本“3”
直到第n个号码。。。
上面的代码片段仅表示需要更换的零件, 其中“文本”和标记可以是任何内容,因为我无法控制html输入

查看当前脚本的外观:

如果我正确理解了您的意思,这将有助于:

临时字符串:

id="1" some text "1",  id="1" some text "1",  id="1" some text "1",
输出:

id="1" some text "1",  id="2" some text "2",  id="3" some text "3",
return temp.replace(/"(\d)"(.*?)"\1"/g, function (all, i, whitespace) {
    n += 1;
    return '"' + n + '"' + whitespace + '"' + n + '"';
});
id="1" some text "1",  id="1" some text "1",  id="1" some text "1",
id="1" some text "1",  id="2" some text "2",  id="3" some text "3",