Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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
Regex 用于在组中捕获数字的sed正则表达式_Regex - Fatal编程技术网

Regex 用于在组中捕获数字的sed正则表达式

Regex 用于在组中捕获数字的sed正则表达式,regex,Regex,输入: 期望输出: "//*[@id='headeritems1']": { "type": "checkbox", "value": "", "selectorType": "xpath" }, "//*[@id='headeritems3']": { "type": "exitPopUp", "value": "", "selec

输入:

期望输出:

"//*[@id='headeritems1']": {
          "type": "checkbox",
          "value": "",
          "selectorType": "xpath"
        },

            "//*[@id='headeritems3']": {

          "type": "exitPopUp",
          "value": "",
          "selectorType": "xpath"
我如何在组中捕获数字标题1和3,而不替换它

我使用的正则表达式:

"(//*[@id='headeritems1'])[2]": {
          "type": "checkbox",
          "value": "",
          "selectorType": "xpath"
        },
        "(//*[@id='headeritems3'])[2]": {
          "type": "exitPopUp",
          "value": "",
          "selectorType": "xpath"

我试过了你的意见。查看并让我知道这是否是您的预期输出。

你好,Sonal,欢迎来到Stack Overflow!将来,您能否使用'backticks'将某些内容格式化为
code
?对于多行代码,每行还可以使用四个空格。无论哪种方式,只要突出显示问题编辑器中的代码,然后单击带括号的按钮,如:{}。谢谢要解析json文件,sed是错误的工具,请使用jq。
sed -i "s/\/\/\*\[@id='headeritems[(\d)]'\]/\"(\/\/\*\[@id='headeritems\1'\])\[2\]/g"