Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular expression flags in procedural cosmetic filters #3372

Closed
Kusresa opened this issue Dec 26, 2017 · 8 comments
Closed

Regular expression flags in procedural cosmetic filters #3372

Kusresa opened this issue Dec 26, 2017 · 8 comments

Comments

@Kusresa
Copy link

Kusresa commented Dec 26, 2017

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.

@gorhill
Copy link
Owner

gorhill commented Dec 31, 2017

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/.

@jspenguin2017
Copy link
Contributor

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

@gorhill
Copy link
Owner

gorhill commented Dec 31, 2017

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.

@jspenguin2017
Copy link
Contributor

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

@Kusresa
Copy link
Author

Kusresa commented Dec 31, 2017

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

Just curious, why is it pointless?

@jspenguin2017
Copy link
Contributor

jspenguin2017 commented Dec 31, 2017

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

@Kusresa
Copy link
Author

Kusresa commented Dec 31, 2017

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)

@jspenguin2017
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants