VSCode regex find & replace submatch math?

前端 未结 6 1933
栀梦
栀梦 2020-11-30 18:34
%s@{fileID: \\(213[0-9]*\\)@\\=\'{fileID: \'.(submatch(1)-1900)@

I am using this regex search and replace command in vim to subtract a constant fro

6条回答
  •  萌比男神i
    2020-11-30 18:44

    For beginners, the accepted answer is correct, but a little terse if you're not that familiar with either VSC or Regex.

    So, in case this is your first contact with either:

    To find and modify text,

    1. In the "Find" step, you can use regex with "capturing groups," e.g. I want to find (group1) and (group2), using parentheses. This would find the same text as I want to find group1 and group2, but with the difference that you can then reference group1 and group2 in the next step:

    2. In the "Replace" step, you can refer to the capturing groups via $1, $2 etc, so you could change the sentence to I found $1 and $2 having a picnic, which would output I found group1 and group2 having a picnic.

    Notes:

    • Instead of just a string, anything inside or outside the () can be a regular expression.

    • $0 refers to the whole match

提交回复
热议问题