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

[Q] how to use and back-reference capture groups?

Open atomGit opened this issue 2 years ago • 4 comments

for example, i want to redirect bitchute embed link to the video page (non-embed) - this isn't working:

https://www.bitchute.com/embed/%r[(.+)]
https://www.bitchute.com/video/$1

atomGit avatar Dec 05 '23 14:12 atomGit

Regexes doesn't work like that in this addon, that you can use capture group in enable url and use the match in the redirect url. Perhaps it's something I can consider adding. I think someone else wanted this too.

So, what you need to do is:

https://www.bitchute.com/embed/
https://www.bitchute.com/video/%p[1]

What I found that Bitchute's embed video has the video id only after /embed/, is that correct? Then you can use the above. Otherwise if there is something else too and you want to use a regex:

https://www.bitchute.com/video/%r[(?:\/embed\/)(.*)]

fluks avatar Dec 05 '23 15:12 fluks

... Bitchute's embed video has the video id only after /embed/, is that correct?

correct, but the example you gave isn't working for me - it's doesn't show up in the menu at all - here's what i'm using:

name: bitchute.com embed to page match: https://www.bitchute.com/embed/ replace: https://www.bitchute.com/video/%p[1] example url: https://www.bitchute.com/embed/VjSfC2hBNL7w/

i suspect the way you've implemented RegEx is easier and results in less code, but personally i don't find it intuitive, such as the above example, or having having to escape ']'

hopefully this doesn't offend you, and i certainly do not mean to do so, but i might suggest having a look at Redirector which uses what i think is a more conventional approach for using both wildcards and RegEx - assuming the code is well written, if you forked that repo, changed the default redirecting to manual and added your auto-redirect option, i think that would be a neary perfect add-on (there's quite a bit of code that could be eliminated to make it lighter)

atomGit avatar Dec 05 '23 15:12 atomGit

Yes, the context menu doesn't open at all when you open that url, but the reason isn't this addon. You can redirect the page using the browser action popup, i.e. the toolbar popup. Or did the context menu open but there was no item for redirecting Bitchute? Or is there an item in browser action popup?

I will look into possibly adding the regex capture group matches be available in the redirect url. And I did choose an easy way to implement regexes, regarding the escaping of ']' or even the whole replacing system. I will need to make a real parser otherwise, which I am not really familiar implementing at.

I can look at Redictor and see if there is something done better than in my addon. You can always criticize, I won't get offended. I made the addon to itch my scratch and maybe the more technical user in mind (I think you are a technical user) naturally, not thinking about having an intuitive UI so much.

fluks avatar Dec 05 '23 17:12 fluks

Or did the context menu open but there was no item for redirecting Bitchute?

correct - when i opened the context menu, the bitchute entry was not there - the redirect also did not happen when i enabled the automatic option in settings

You can always criticize, I won't get offended.

glad to hear it - i didn't want to offend you :)

atomGit avatar Dec 05 '23 20:12 atomGit

Now these should work if you use Always redirect on Chrome. Not otherwise though, at least for now.

fluks avatar Oct 19 '24 13:10 fluks

Okay, I tried implementing these and it was actually very easy. At least with Firefox, I'm not sure about Chrome, if I remember correctly it has already different systems for Enable URLs with and without Always. So, this would only affect without Always on Chrome. And both cases on Firefox. I will release new version with this feature shortly.

Thanks about the suggestion.

Edit: And how you would use these is if you use capturing groups in Enable URL like:

(a.c)

Then you can use the captured group in redirect URL:

foo%g[1]bar

fluks avatar Mar 07 '25 16:03 fluks

New Firefox version is released and on Chromium soon too once it's reviewed.

fluks avatar Mar 08 '25 15:03 fluks