Writing a regex..

Off-topic posts of interest to the "Everything" community.
Post Reply
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Writing a regex..

Post by harryray2 »

I'm using an addon for Firefox called redirector.

It automatically redirects to user defined urls on certain pages. It accepts both wildcards and regex.
One of the wildcard redirects I use is:

Include pattern: https://voe*.*/*
Redirect to: https://9xbuddy.org/process?url=https://voe.sx/$3

I'm trying to write a regex equivalent but I can't quite seem to get it right.

Any ideas please?
Attachments
Image 001.jpg
Image 001.jpg (45.44 KiB) Viewed 10842 times
void
Developer
Posts: 16753
Joined: Fri Oct 16, 2009 11:31 pm

Re: Writing a regex..

Post by void »

For wildcards to regex, please try:
replacing * with .*
and replacing . with \.

https://voe.*\..*/.*

Looks like they support group captures too, so maybe something like:

https://voe.*\..*/(.*)

and then use \1 (or maybe they use $1?) in "Redirect to" to recall the text matched inside ()
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Re: Writing a regex..

Post by harryray2 »

Thanks so much, I think I've got it...

Include pattern: https://voe.*\..*/(.*)
Redirect to: https://9xbuddy.org/process?url=https://voe.sx/$1?

I'm afraid that regex makes my head spin :0)
raccoon
Posts: 1017
Joined: Thu Oct 18, 2018 1:24 am

Re: Writing a regex..

Post by raccoon »

If it helps, here's the translation from the globbing wildcards you're already familiar with to their regex equivalent.

Code: Select all

               glob    regex
    wildchar:  ?       .
    wildcard:  *       .*
      period:  .       \.
 stardotstar:  *.*     .*\..*
  stardotexe:  *.exe   .*\.exe
   backslash:  \       \\
   foreslash:  /       \/
 colonbacksl:  c:\     c:\\
  slashslash:  ftp://  ftp:\/\/
You may also have to escape your slashes with backslashes in your filters for it to work.
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Re: Writing a regex..

Post by harryray2 »

Thanks a lot, that should help... The problem I was having was capturingthe characters at the end.

eg: https://voeun-block.net/qiqqffsxdtu5

The wildcard part was relatively easy to work out but I couldn't seem to get the qiqqffsxdtu5 part to appear, what I was getting was https://voe.sx/$1?, instead of https://voe.sx/qiqqffsxdtu5

The (.*) as suggested by void solved the problem.
Post Reply