Tadas Valatkevičius
Tadas Valatkevičius

Reputation: 21

Replace with whole match value using Notepad++ regex search and replace

I am using the following expression:

Find what: [0-9]

But what should I write in Replace with field if I want to add specific sup tag to all the digits?

Thanks in advance!

Upvotes: 2

Views: 876

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626896

The replacement can be

<sup>$0</sup>

or

<sup>$&</sup>

Note that the $0 / ${0} / $&, or even $MATCH and ${^MATCH} backrefrence inserts the whole match.

See the Substitutions section:

$&, $MATCH, ${^MATCH}
       The whole matched text.

and

$n, ${n}, \n
      Returns what matched the subexpression numbered n. Negative indices are not alowed.

Note that a match value is usually stored as Group 0 inside a match object.

However, \0 as of now does not work (Notepad++ v.6.9), it looks like it is treated as a NUL character and truncates the replacement pattern right at the location where it is located.

Upvotes: 4

Related Questions