Find and replace regex in Intellij, but keep some of the matched regex?

前端 未结 1 841
梦如初夏
梦如初夏 2021-01-02 00:25

I changed an array to a list, so I want to change all instances of myObject[index] to myObject.get(index) where index is different integers. I can

相关标签:
1条回答
  • 2021-01-02 01:10

    Use the following regex replacement:

    Find: myObject\[(.*?)\]
    Replace: myObject.get($1)

    If the index is an integer, you may replace (.*?) with (\d+).

    The pair of unescaped parentheses creates a capturing group that we may reference from the replacement pattern using $ + Group ID. $1 will insert the index into the replacement result.

    0 讨论(0)
提交回复
热议问题