Forums

Home › Forums › Parental Control › pcWRT support for complex RegEx

pcWRT support for complex RegEx

Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #7467
    Casino
    Participant

    pcWRT supports RegEx formatted like this:

    ~^(www\.)?amazon\.[a-z]{2,}(\.[a-z]{2,})?$

    My goal is to block only the main domains while leaving subdomains unblocked. For example, I want to block “amazon.com” but not “aws.amazon.com”, “music.amazon.com”, etc.

    Currently, I am using this RegEx:

    ~^www.amazon.\.*

    I was wondering, firstly, if the complex RegEx mentioned at the start of this discussion is supported by pcWRT, and secondly, if this other one:

    ~^(www\.)?amazon\.

    is the most comprehensive option—both in terms of clean syntax and efficiency (i.e., without placing too heavy a load on the router’s hardware).

    #7469
    support
    Keymaster

    First of all, ^ matches the beginning of the string. ~^www.amazon.com will match www.amazon.com but not 1www.amazon.com or a.www.amazon.com. Remember on pcWRT router, the dot without a leading \ matches the dot itself (unlike the standard regex, which matches any single character).

    ^(www.)?amazon.com matches both www.amazon.com and amazon.com (i.e., the grouping with a question mark matches the group 0 or 1 times).

    ~^www.amazon.\.* matches anything starting with www.amazon., e.g., www.amazon.com, www.amazon.us, www.amazon.eu etc.

    ~^(www\.)?amazon\.: the \ preceding the dot changes the meaning of the dot to match any single character. So this regex will match amazon.com, amazon-with-anything-else-here, because there is no end of string anchor $. Apparently, you want the dot to be a literal match here. Thus the correct regex should be: ~^(www.)?amazon., which would match amazon.anything-here, www.amazon.anything-here. But it would not match www.amazonaws.com, because a dot must follow amazon, not an a (in aws).

    #7470
    Casino
    Participant

    Could you please tell me if pcWRT supports the first, complex RegEx I wrote at the beginning of my post?

    Here is the issue I’m facing: I want to block only the main Amazon domains (such as amazon.it, amazon.com, amazon.es) while leaving all their subdomains unblocked.

    I am currently using this RegEx:

    ~^www.amazon.\.*

    but this also seems like a valid alternative:

    ~^(www\.)?amazon\..*$

    Could you recommend the most suitable RegEx for this purpose?

    #7471
    support
    Keymaster

    ~^(www.)?amazon. will block all domains starting with amazon., including amazon.it, amazon.com, amazon.es, plus www.amazon.*. But it will not block other subdomains besides www.

    #7472
    Casino
    Participant

    I asked some specific questions that haven’t been answered, but never mind. Could you give me a practical example of what this RegEx blocks and doesn’t block?

    ~^www.amazon.\.*

    And what this other one blocks and doesn’t block?

    ~^(www\.)?amazon\..*$

    That way, I’ll be able to understand the practical difference and apply it to other domains. Thanks.

    #7473
    support
    Keymaster

    You can ask AI (e.g., Google) and get a good explanation, with a prompt like this:

    The following is a POSIX regex. The only exception is . is a literal dot, but \. is a meta-character that matches a single character. What does it match: ^www.amazon.\.*

    #7474
    Casino
    Participant

    I asked you here precisely because AI always returns wrong solutions.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.