0

I have seen the instructions on using $1 in order to backreference the replace, but it is not working for me. Example:

I search for

<header

to replace with

$1 class="bold"

and instead of <header class="bold" I get $1 class="bold"

Am I missing something?

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
RKichenama
  • 364
  • 5
  • 10

1 Answers1

4

You must understand that $n refer to the capturing group number n. Since you don't have capturing groups in your search pattern, the group number 1 doesn't exist:

You must use capturing parenthesis to define a group, example:

search:  (<header)
replace: $1 class="bold"

Another example:

search:  (<)(header)
replace: $1$2 class="bold"

Notice: $0 refers to the whole match (without define any capturing group). Then you can write:

search:  <header
replace: $0 class="bold"
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125