Re-wrote my answer to
- Add new use-case OP added where some values have the X prefix and must not be replaced.
- I was initially putting the double quote character in brackets when there was no need.
The first case I answered is where none of the HREF values already have the X prefix.
Find:
href="([^"]*)\.rock"
And replace:
href="X\1.rock"
Start:
<Music href="6000111.genre" title="AAA">
<Music format="ditamap" href="000760.rock" title="222"/>
<Music format="ditamap" href="000756.rock" title="333"/>
</Music>
Finish:
<Music href="6000111.genre" title="AAA">
<Music format="ditamap" href="X000760.rock" title="222"/>
<Music format="ditamap" href="X000756.rock" title="333"/>
</Music>
Screen shot showing this first result is below.
Breakdown of the regex:
- Find:
href="([^"]*)\.rock"
href="
- this findshref="
([^"]*)
- this creates the first backreference - tells the engine to look for and remember everything between the brackets:[^"]*
so that we can reference it in the replace part.[^"]
- this part of the pattern says any character that is not a double quote.- And the asterisk at the end of
[^"]*
is a repetition pattern that says look for zero or more characters that matches the thing just before it (so find zero or more characters that are not a double quote).
\.rock"
this defines the rest of the pattern which must be.rock"
- Note that I have escaped the period character:
\.
. That is because period has a special meaning in a regex and we are telling the regex that we mean a literal dot or period.
- Replace:
href="X\1.rock"
href="X
- says to output literallyhref="X
..\1
- says to replace\1
with the first backreference we created (zero or more characters that are not a double quote)..rock"
- says to output literally.rock"
.- Note that I didn't need to escape the period here, because it doesn't have the same meaning in replace - it just means the literal dot.
The second case is in response to OP's comment that some of the HREF values already have the X prefix. In this case, change the regex as below.
Find:
href="([^X][^"]*)\.rock"
And replace:
href="X\1.rock"
Start:
<Music href="6000111.genre" title="AAA">
<Music format="ditamap" href="000760.rock" title="222"/>
<Music format="ditamap" href="X000756.rock" title="333"/>
<Music format="ditamap" href="000757.rock" title="444"/>
<Music format="ditamap" href="X000758.rock" title="555"/>
<Music format="ditamap" href="000759.rock" title="666"/>
</Music>
Finish:
<Music href="6000111.genre" title="AAA">
<Music format="ditamap" href="X000760.rock" title="222"/>
<Music format="ditamap" href="X000756.rock" title="333"/>
<Music format="ditamap" href="X000757.rock" title="444"/>
<Music format="ditamap" href="X000758.rock" title="555"/>
<Music format="ditamap" href="X000759.rock" title="666"/>
</Music>
Screen shot showing this second result is below.
Breakdown of the regex:
- Find:
href="([^X][^"]*)\.rock"
href="
- this findshref="
([^X][^"]*)
- this creates the first backreference - tells the engine to look for and remember everything between the brackets:([^X][^"]*)*
so that we can reference it in the replace part.[^X]*
- this part of the pattern says any character that is not an X.[^"]
- this part of the pattern says any character that is not a double quote.- And the asterisk at the end of
[^"]*
is a repetition pattern that says look for zero or more characters that matches the thing just before it (so find zero or more characters that are not a double quote).
\.rock"
this defines the rest of the pattern which must be.rock"
- Note that I have escaped the period character:
\.
. That is because period has a special meaning in a regex and we are telling the regex that we mean a literal dot or period.
- Replace:
href="X\1.rock"
href="X
- says to output literallyhref="X
..\1
- says to replace\1
with the first backreference we created (zero or more characters that are not a double quote)..rock"
- says to output literally.rock"
.- Note that I didn't need to escape the period here, because it doesn't have the same meaning in replace - it just means the literal dot.