redirect-link icon indicating copy to clipboard operation
redirect-link copied to clipboard

Replace characters with different ones

Open Nine-Theta opened this issue 7 months ago • 6 comments

Is there a way to replace part of the URL with something else? I have some old forums links I want to visit but the formatting has changed over the years

specifically the old URL is something like this: https://www.example.com/forum/some~thread~title?postId=1 And redirect URL should replace the '~' with '%20'

Nine-Theta avatar May 02 '25 02:05 Nine-Theta

I don't think there's a way to do that, since title can have any number of tildes in it I presume.

I think I can add replacement feature. Once I come up with its functionality and syntax.

fluks avatar May 02 '25 06:05 fluks

I guess I can do syntax like %e[/~/%20/g] to keep the syntax as close as possible to regexes and then use String.replace(). Perhaps that is useful enough. And should it match against the whole URL then. Something like %p[1]%e[/~/%20/g] could also be nice, what I mean is that if there is a format before %e format, then that format's output will be used for %e's input, otherwise %e's input will be the whole URL. Maybe too complex.

fluks avatar May 02 '25 06:05 fluks

Being able to replace just the part of selected format would be really helpful though

Nine-Theta avatar May 02 '25 18:05 Nine-Theta

In your case %e[/~/%20/g] this would be good enough? But I can imagine there would be other cases where it wouldn't be enough. Having formats as input for replace format makes the code quite a lot more complex but it would be a lot more powerful.

fluks avatar May 05 '25 17:05 fluks

Correct me if I'm misunderstanding, but wouldn't %e[/~/%20/g] return the entire URL with all instances of ~ being replaced? While fine in the example, wouldn't it also effectively lock you out of using other formats?

For my actual real world use-case I also need to replace the hostname, as the forum is hosted elsewhere now, and they switched the ?postId=1 query to just a /1. These I can already solve right now with the extension, but I feel like they would conflict with %e as is.

For clarity: https://www.example.com/forum/some~thread~title?postId=1 should become: https://www.newhost.com/forum/some%20thread%20title/1

Nine-Theta avatar May 05 '25 19:05 Nine-Theta

Correct me if I'm misunderstanding, but wouldn't %e[/~/%20/g] return the entire URL with all instances of ~ being replaced?

Yes, that's correct.

While fine in the example, wouldn't it also effectively lock you out of using other formats?

Pretty much, that's the downside.

I'll implement using other formats as input for %e and see how it behaves.

fluks avatar May 06 '25 10:05 fluks

A new version with this feature should be soon available. With the other format used as input for %e format feature also. Hopefully it works as expected.

fluks avatar Jun 12 '25 20:06 fluks