sed Regex用于捕获组中的数字

时间:2018-08-09 19:23:55

标签: regex

输入:

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

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

          "type": "exitPopUp",
          "value": "",
          "selectorType": "xpath"

所需的输出:

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

如何捕获组中的数字标题项目1和3,而不是替换它们。

我使用的正则表达式:

sed -i "s/\/\/\*\[@id='headeritems[(\d)]'\]/\"(\/\/\*\[@id='headeritems\1'\])\[2\]/g"

1 个答案:

答案 0 :(得分:0)

我尝试针对此regex输入您的信息。检查一下,让我知道这是否是您的预期输出。