Also at the end the echo %url% requires to be echo !url! on my system.
With echo %url% I just get '='.
That is because you changed
set "repl=^&" to
set repl=&. Quotes and caret are both necessary if you want to use %url% at the end. Batch scripting has special characters and & in a string is notorious. (Did you not see the output listing I made?)
Briefly, when the command interpreter encounters certain "special characters" it treats them as control characters unless you make special arrangements. Usually this means "escaping" them. The caret (^) is the escape used for most special characters but some are differently escaped.
For example (you can try stuff like this out at the prompt)
A single ampersand is the command separator so an unescaped one means "everything after me is a new command" e.g. cls & dir & echo hello world
1. Ampersand (&) unescaped, setting the variable fails
c:\>set string=cats & dogs
'dogs' is not recognized as an internal or external command,
operable program or batch file.
c:\>
2. Escaped in the SET statement, so that works...
c:\>set string=cats ^& dogs
c:\>
but look what happens when we try to expand the variable
c:\>echo %string%
cats
'dogs' is not recognized as an internal or external command,
operable program or batch file.
c:\>
3. We both escape the & with a caret and enclose the assignment portion of the SET statement with quotes
The assignment works...
c:\>set "string=cats ^& dogs"
c:\>
So does the expansion...
c:\>echo %string%
cats & dogs
c:\>
Excellent page at
http://www.robvanderwoude.com/escapechars.php where I got this table:
Escape Characters
Character to be Escape Remark
to be escaped sequence
% %% May not always be required in doublequoted strings, just try
^ ^^ May not always be required in doublequoted strings, but it won't hurt
& ^&
< ^<
> ^>
| ^|
' ^' Required only in the FOR /F "subject" (i.e. between the parenthesis), unless backq is used
` ^` Required only in the FOR /F "subject" (i.e. between the parenthesis), if backq is used
, ^, Required only in the FOR /F "subject" (i.e. between the parenthesis), even in doublequoted strings
; ^;
= ^=
( ^(
) ^)
! ^^! Required only when delayed variable expansion is active
\ \\ Required only in the regex pattern of FINDSTR
[ \[
] \]
" \"