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

Comments

Projects
None yet
3 participants
@Kusresa

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 gorhill closed this in 17dfec5 Dec 30, 2017

@gorhill

This comment has been minimized.

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

This comment has been minimized.

Contributor

jspenguin2017 commented Dec 31, 2017

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

@jspenguin2017 jspenguin2017 referenced this issue Dec 31, 2017

Open

Nano Linter issues mega thread #1

0 of 6 tasks complete
@gorhill

This comment has been minimized.

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

This comment has been minimized.

Contributor

jspenguin2017 commented Dec 31, 2017

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

@Kusresa

This comment has been minimized.

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

This comment has been minimized.

Contributor

jspenguin2017 commented Dec 31, 2017

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

@Kusresa

This comment has been minimized.

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

This comment has been minimized.

Contributor

jspenguin2017 commented Dec 31, 2017

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