in reply to replace characters in link

You could use URI to safely parse and modify those kinds of strings.

use warnings; use strict; use URI; my $input = 'https://abc.abc:8080/abc?abcdef&abc=&egh?'; my $uri = URI->new($input); $uri->host('def.def'); $uri->port(undef); my $output = "$uri"; use Test::More; my $expect = 'https://def.def/abc?abcdef&abc=&egh?'; is $output, $expect or diag explain $output; done_testing;

Replies are listed 'Best First'.
Re^2: replace characters in link
by ytjPerl (Scribe) on Dec 11, 2018 at 15:56 UTC
    does it need to escape the special character for the input in this case? Actually my input is dynamic.
      does it need to escape the special character for the input in this case? Actually my input is dynamic.

      That depends on what special character you mean? URI should be able to handle just about any supported URI you throw at it. Can you show some more examples of what you mean? In fact, my example code includes Test::More, and you can easily extend it with more test cases to see if it does what you want.

      Also, please be careful, you've reposted your question twice now. If you have the browser open to the submission page, don't reload it.