Page 1 of 1

Regular expression issue

Posted: Sat Jan 15, 2011 11:06 am
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

Re: Regular expression issue

Posted: Sat Jan 15, 2011 11:37 am
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).

Re: Regular expression issue

Posted: Sat Jan 15, 2011 4:54 pm
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.

Re: Regular expression issue

Posted: Sat Jan 15, 2011 5:24 pm
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)/