regex replace keeping a part of a string

Today I managed to replace (in html file links and anchors) absolute paths with relative ones.

I needed to keep the anchors and links number.

I did so:

search: href="#_ftn([0-9])">
replace: href="#_ftnref\1" id="_ftn\1">

In this way href=”#_ftn1 was replaced by  href="#_ftnref1" id="_ftn1", href=”#_ftn2 was replaced by  href="#_ftnref2" id="_ftn2", and so on.

For numbers with two digits

replacehref="#_ftnref\1" id="_ftn\1">

Only the search string is to be modified, if you have more digits (f.e. [0-9][0-9][0-9][0-9] if you have numbers with four digits, such as 1276), not the replace one (so don’t write \1\1

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *