Forcing case sensitivity

Posting here is no longer possible, please use the forum of a filter list project, such as EasyList
Locked
Zzedar

Forcing case sensitivity

Post by Zzedar »

Is there any way to force a particular (RegExp) filter to be case-sensitive? I want to have

/[a-z]A[Dd]\d/

That is, I want it to look for any lower-case letter, then either, then the word "Ad" with a capital "A", then a number. As it is, it'll match things like "read2.gif". I tried

/(?-1)[a-z]A[Dd]\d/

but it didn't work.
kustodian

Post by kustodian »

Try adding 'g' at the end of the expressions like this:

/[a-z]A[Dd]\d/g

or

/(?-1)[a-z]A[Dd]\d/g

I didn't try if they work, but it should work.
User avatar
pirlouy
Posts: 332
Joined: Sat Jun 10, 2006 2:33 pm
Location: France

Post by pirlouy »

I don't think WP has added this feature.

Anyhow, I don't think case sensitive is a good conception.
Zzedar

Post by Zzedar »

kustodian wrote:Try adding 'g' at the end of the expressions like this:

/[a-z]A[Dd]\d/g

or

/(?-1)[a-z]A[Dd]\d/g

I didn't try if they work, but it should work.
Two problems with that: first, you can't add tags that way here, since if the concluding character isn't a slash, it won't be recognized as RegEx. Second, why would making it a global search have any impact on case sensitivity?
kustodian

Post by kustodian »

Zzedar wrote:Two problems with that: first, you can't add tags that way here, since if the concluding character isn't a slash, it won't be recognized as RegEx. Second, why would making it a global search have any impact on case sensitivity?
Good point :(
I forgot that RegEx is case sensitive by default (but not in ABP) :oops:
Zzedar

Post by Zzedar »

Okay, here's what (I think) I've figured out:

The problem is from adblockplus.jar/content/prefs.js

Code: Select all

regexp = new RegExp(regexp, "i");
			if (hash.has(regexp))
				return;
This applies the "i" flag to the regex when converting it into the form used by Adblock, making it case-insensitive. What makes me nervous about this is this statement from the Core Reference:
The value of ignoreCase is true if the "i" flag was used; otherwise, false. The "i" flag indicates that case should be ignored while attempting a match in a string.

You cannot change this property directly.
This seems to indicate that I can't use modifiers in the expression itself to override that "i". I suppose I could change the line to remove that "i", but I don't want to mess with the code since I don't really know much about how it works.
Wladimir Palant

Post by Wladimir Palant »

Yes, regexps are always case-insensitive - that's how Adblock works and Adblock Plus has to do the same for backwards compatibility.
Locked