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

Add support for RegEx capturing groups

Open Clozent opened this issue 1 year ago • 6 comments

I couldn't notice that I can't use regex capturing groups from the URL to match (the one in the " Enable URL" column) in the URL the extension redirects to.

One way to implement it is by having a toggle that says that the URL (the one in the "URL" column) should be using the RegEx substitution format. Turning on the toggle will make it so the redirect URL won't be able to use the custom formats (such as %p or %u). It will be purely RegEx.

Another way is to have a separate format, like %c[] that will use the RegEx substitution format with capturing groups from the matched URL inside it, although this might cause problems because of the square brackets (I'm not sure, though).

Clozent avatar Sep 02 '23 17:09 Clozent

You can use capturing groups in the redirect URL where the match of a capturing group is added into the redirect URL. There's an example in the proposed redirects issue: https://securityscorecard.com/security-rating/%r[(?:https?:\/\/)(?:[^\.\]+\.)?([^\.\/\]+\.[^\.\/\]+)]. Or do you mean using the capturing group match in the regex, for example: %r[aaa(.*)bbb$1]?

fluks avatar Sep 03 '23 11:09 fluks

What I meant was using capturing groups from the "Example URL" column of a redirect in the "URL" column of that redirect.

Clozent avatar Sep 03 '23 11:09 Clozent

Using capturing group in Enable URL and use that match in URL? I don't understand why would you want that because the Enable URL will be the same as you can match against in URL.

You want this?

Actual URL: abc Enable URL: a(.*)c URL: x.z/$1

But you can do the same with:

Actual URL: abc Enable URL: a.c URL: x.z/%r[a(.)c]

It's a little more work though with current implementation.

fluks avatar Sep 03 '23 14:09 fluks

To answer your question of if this is what I want, your example is exactly that. I want to be able to use specific parameters from the actual URL, that were matched by the RegEx in the Enable URL.

Clozent avatar Sep 04 '23 11:09 Clozent

Is there a reason you don't want to use the way I showed later in the example? It doesn't work at all or is it too difficult?

fluks avatar Sep 08 '23 03:09 fluks

I want this simply because it would be more convenient and straightforward to do in some cases, since you won't need to reuse RegEx. It would also improve clarity (since you can see which part of the URL is used by identifying the capturing group).

Clozent avatar Sep 21 '23 11:09 Clozent