Skip to content

Regular expression flags in procedural cosmetic filters #3372

Closed

Description

@Kusresa

Currently, it looks like the procedural cosmetic filter that can take in regex are not able to take in other trailing flags such as /g /i /m or even within the regex like /(?i)example/.

Can support for these be added? They can improve efficiency of rules that can use them and reduce filter length/number of some filters.

Activity

  1. gorhill commented on Dec 31, 2017

    @gorhill
    Owner

    The syntax is the same a literal javascript regex flags:

    example.com##body:has-text(/PRIOR/i)
    

    Only two flags are supported: i and m (support for g is pointless).

    I partially checked with some filter lists known to use procedural selectors and I could not find any ambiguity. If ever someone needs to lookup for a string literal like /ad/im, the solution is to use a regular expression to work around flag parsing: /\/ad\/im/.

  2. jspenguin2017 commented on Dec 31, 2017

    @jspenguin2017
    Contributor

    Would /ad/im* be parsed as string literal or still RegExp?

  3. gorhill commented on Dec 31, 2017

    @gorhill
    Owner

    String literal. I don't want special syntax such as wildcards -- that is why regex literals are supported, to take care of when a string literal is not enough.

  4. jspenguin2017 commented on Dec 31, 2017

    @jspenguin2017
    Contributor

    So the proper solution to make /ad/im a string literal would be add a trailing wildcard?

  5. Kusresa commented on Dec 31, 2017

    @Kusresa
    Author

    Only two flags are supported: i and m (support for g is pointless).

    Just curious, why is it pointless?

  6. jspenguin2017 commented on Dec 31, 2017

    @jspenguin2017
    Contributor

    If it matches it matches, doesn't matter how many times.

  7. Kusresa commented on Dec 31, 2017

    @Kusresa
    Author

    So am I to understand that the g flag isn't needed because uBO already will find all matches and not just stop after the first match? (please correct me if I'm wrong)

  8. jspenguin2017 commented on Dec 31, 2017

    @jspenguin2017
    Contributor

    You only need to match once for the filter to trigger.

  9. added a commit that references this issue on Jul 16, 2026
    83a2e54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions