Hello, @musocity, @coises and All,
@musocity, I must admit that I shoud have remembered that an HTML link is always defined by a <a> tag, whose the href attribute specifies the link’s destination :-(
But, in your first post, you textually said :
So =POPSONG will link to
httXX://mysongs.com/songs/=POPSONG.mp3
Which is exactly what I did, in my second reply to you !!
Now, if you had posted something like :
I have a lot of <tr> blocks which, each, defines a song’s name, after the <td>/= chars
For instance, I have this INPUT text :
<tr>
<td>=POPSONG</td>
<td>R</td>
<td>4/4</td>
<td>ev8</td>
<td>140</td>
<td>Pop Piano Lite Solo Piano</td>
<td>Ballad</td>
<td>Pop 20</td>
<td>2009/12</td>
<td>RT 70</td>
<td>2</td>
<td>2</td>
<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
</tr>
and I would like to get this OUTPUT :
<tr>
<td><a href="https://mysongs.com/songs/=POPSONG.mp3" title="">=POPSONG</a></td>
<td>R</td>
<td>4/4</td>
<td>ev8</td>
<td>140</td>
<td>Pop Piano Lite Solo Piano</td>
<td>Ballad</td>
<td>Pop 20</td>
<td>2009/12</td>
<td>RT 70</td>
<td>2</td>
<td>2</td>
<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
</tr>
I could have given you the exact answer, straight away !
Now, regarding the replacement of some punctuation chars by their %encoded equivalent :
I did not consider the -, ~, _ chars and the . dot if followed with mp3, which are non-reserved chars, as well as word chars
I did not consider, either, the " double-quotes as well as the < and > chars, extensively used in HTML files
Thus, the remaining characters to test are this list :
!#$ %&'()*+,/:;=?@[]^`{|}
Then, I chose this odd name’s song :
!#$ Name%&of'()*+,/:;the=?@[]song^`{|}
Followed by .mp3
I found out a regex S/R which treats all these characters and replace them by their %encoded equivalent, in one go :
- SEARCH (?:/=|>=|(?<!\A)\G)(?:(?s-i)(?!\.mp3|</a>).)*?\K(?:(\x20)|(!)|(#)|(\$)|(%)|(&)|(')|(\()|(\))|(\*)|(\+)|(,)|(/)|(:)|(;)|(=)|(\?)|(@)|([)|(\\)|(])|(\^)|(`)|(\{)|(\|)|(\})|(\.(?!mp3)))
- REPLACE (?{1}%20)(?{2}%21)(?{3}%23)(?{4}%24)(?{5}%25)(?{6}%26)(?{7}%27)(?{8}%28)(?{9}%29)(?{10}%2A)(?{11}%2B)(?{12}%2C)(?{13}%2F)(?{14}%3A)(?{15}%3B)(?{16}%3D)(?{17}%3F)(?{18}%40)(?{19}%5B)(?{20}%5C)(?{21}%5D)(?{22}%5E)(?{23}%60)(?{24}%7B)(?{25}%7C)(?{26}%7D)(?{27}%2E)
I took inspiration from this post :
https://community.notepad-plus-plus.org/topic/22690/generic-regex-replacing-in-a-specific-zone-of-text
To test this regex :
First, copy the
following text in a
new tab
<tr>
<td><a href="https://mysongs.com/songs/=!#$ Name%&of'()*+,/:;the=?@[]song^`{|}.mp3" title="">=!#$ Name%&of'()*+,/:;the=?@[]song^`{|}</a></td>
<td>R</td>
<td>4/4</td>
<td>ev8</td>
<td>140</td>
<td>Pop Piano Lite Solo Piano</td>
<td>Ballad</td>
<td>Pop 20</td>
<td>2009/12</td>
<td>RT 70</td>
<td>2</td>
<td>2</td>
<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
</tr>
<tr>
<td><a href="https://mysongs.com/songs/=!#$ Name%&of'()*+,/:;the=?@[]song^`{|}.mp3" title="">=!#$ Name%&of'()*+,/:;the=?@[]song^`{|}</a></td>
<td>R</td>
<td>4/4</td>
<td>ev8</td>
<td>140</td>
<td>Pop Piano Lite Solo Piano</td>
<td>Ballad</td>
<td>Pop 20</td>
<td>2009/12</td>
<td>RT 70</td>
<td>2</td>
<td>2</td>
<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
</tr>
Move to the very beginning of the file ( IMPORTANT )
Open the Replace dialog ( Ctrl + H )
Un-tick all box options
- SEARCH (?:/=|>=|(?<!\A)\G)(?:(?s-i)(?!\.mp3|</a>).)*?\K(?:(\x20)|(!)|(#)|(\$)|(%)|(&)|(')|(\()|(\))|(\*)|(\+)|(,)|(/)|(:)|(;)|(=)|(\?)|(@)|([)|(\\)|(])|(\^)|(`)|(\{)|(\|)|(\})|(\.(?!mp3)))
- REPLACE (?{1}%20)(?{2}%21)(?{3}%23)(?{4}%24)(?{5}%25)(?{6}%26)(?{7}%27)(?{8}%28)(?{9}%29)(?{10}%2A)(?{11}%2B)(?{12}%2C)(?{13}%2F)(?{14}%3A)(?{15}%3B)(?{16}%3D)(?{17}%3F)(?{18}%40)(?{19}%5B)(?{20}%5C)(?{21}%5D)(?{22}%5E)(?{23}%60)(?{24}%7B)(?{25}%7C)(?{26}%7D)(?{27}%2E)
Select the Regular expression search mode
Click once, on the Replace All button ( Do not use the Replace button )
Important :
Due to the presence of the \K syntax, in the search regex, you CANNOT use the Replace button and must trigger a global replacement !
If you just want to know the different occurrences, which will be replaced later, simply use the Find Next or Find Previous button ( or F3 / Shift + F3 )
And you should get this OUTPUT :
<tr>
<td><a href="https://mysongs.com/songs/=%21%23%24%20Name%25%26of%27%28%29%2A%2B%2C%2F%3A%3Bthe%3D%3F%40%5B%5C%5Dsong%5E%60%7B%7C%7D.mp3" title="">=%21%23%24%20Name%25%26of%27%28%29%2A%2B%2C%2F%3A%3Bthe%3D%3F%40%5B%5C%5Dsong%5E%60%7B%7C%7D</a></td>
<td>R</td>
<td>4/4</td>
<td>ev8</td>
<td>140</td>
<td>Pop Piano Lite Solo Piano</td>
<td>Ballad</td>
<td>Pop 20</td>
<td>2009/12</td>
<td>RT 70</td>
<td>2</td>
<td>2</td>
<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
</tr>
<tr>
<td><a href="https://mysongs.com/songs/=%21%23%24%20Name%25%26of%27%28%29%2A%2B%2C%2F%3A%3Bthe%3D%3F%40%5B%5C%5Dsong%5E%60%7B%7C%7D.mp3" title="">=%21%23%24%20Name%25%26of%27%28%29%2A%2B%2C%2F%3A%3Bthe%3D%3F%40%5B%5C%5Dsong%5E%60%7B%7C%7D</a></td>
<td>R</td>
<td>4/4</td>
<td>ev8</td>
<td>140</td>
<td>Pop Piano Lite Solo Piano</td>
<td>Ballad</td>
<td>Pop 20</td>
<td>2009/12</td>
<td>RT 70</td>
<td>2</td>
<td>2</td>
<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
</tr>
Final clarification :
Do
not run this S/R
twice ! Indeed, any
% char of the
encoded chars would be
encoded as
%25 again !
Best Regards,
guy038