Regular expression issue

Ask for help about NoScript, no registration needed to post
Dukeswharf
Posts: 13
Joined: Mon Nov 08, 2010 5:24 pm

Regular expression issue

Post by Dukeswharf »

Can anyone enlighten me as to why the following would not work in 'https -> force the following sites'?:

https://(?:encrypted|mail|docs)\.google\./(?:com|co\.uk)\b.*

or

(?:encrypted|mail|docs)\.google\./(?:com|co\.uk)\b.*

Many thanks in advance
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET4.0C)
User avatar
Giorgio Maone
Site Admin
Posts: 9455
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: Regular expression issue

Post by Giorgio Maone »

Dukeswharf wrote:Can anyone enlighten me as to why the following would not work in 'https -> force the following sites'?:

https://(?:encrypted|mail|docs)\.google\./(?:com|co\.uk)\b.*

or

(?:encrypted|mail|docs)\.google\./(?:com|co\.uk)\b.*

Many thanks in advance
There's an extra (wrong) slash after "google\.", which causes both pattern to match an hypothetical (and unlikely) "google./com" rather than "google.com/".

Also, the first pattern will never match what it's meant to match (a plain HTTP request to be turned into HTTPS), while it may match false positives where https:// is not anchored to the beginning of the URL.

Better

Code: Select all

^https://(?:encrypted|mail|docs)\.google\.(?:com|co\.uk)/
Notice the leading "^" (left anchor) and the missing trailing .* (you don't need it, since the pattern is not right anchored).
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Dukeswharf
Posts: 13
Joined: Mon Nov 08, 2010 5:24 pm

Re: Regular expression issue

Post by Dukeswharf »

Many thanks for the clarification.

I have noticed that, in firefox error console, an [NoScript HTTPS] Forced URI https://[selection].com is not generated for any of 'or' selections, which is the case if I simply write *.google.com, for example.

Is this an issue or normal behavior?

Many thanks in advance.
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET4.0C)
User avatar
Giorgio Maone
Site Admin
Posts: 9455
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: Regular expression issue

Post by Giorgio Maone »

Dukeswharf wrote:Is this an issue or normal behavior?
It's an issue with my regexp, which contained a typo.
In fact, I wrote
Giorgio Maone wrote: Also, the first pattern will never match what it's meant to match (a plain HTTP request to be turned into HTTPS)
but in the end I gave you an useless ^https: regexp anyway.

Obviously it should have been

Code: Select all

^http://(?:encrypted|mail|docs)\.google\.(?:com|co\.uk)/
instead, or even

Code: Select all

^[^:]+://(?:encrypted|mail|docs)\.google\.(?:com|co\.uk)/
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Post Reply