Author Topic: Pattern Example incorrect?  (Read 15205 times)

Offline tanstaafl

  • God Member
  • ******
  • Posts: 1363
Pattern Example incorrect?
« on: October 24, 2007, 06:52:53 PM »
Hey Eric...

I don't use regex patterns, but I think the one that is on the Pattern Creation windows is wrong...

I'm clueless when it comes to regex and escaping characters, but, in the example, all of the dots (.) are escaped, except the very last one...

Shouldn't that last escape character be after the last slash, and before the trailing dot (the one right before the asterisk)?

Offline Eric H. Jung

  • grimholtz
  • Administrator
  • *****
  • Posts: 3353
Re: Pattern Example incorrect?
« Reply #1 on: October 24, 2007, 07:56:49 PM »
Are you talking about this page? If not, then what? If yes, then which example?

Offline tanstaafl

  • God Member
  • ******
  • Posts: 1363
Re: Pattern Example incorrect?
« Reply #2 on: October 24, 2007, 08:55:59 PM »
No, sorry - I'm talking about the add/edit pattern window in the extension... see below...

Offline Miquel 'Fire' Burns

  • Administrator
  • *****
  • Posts: 1157
  • Programmer
Re: Pattern Example incorrect?
« Reply #3 on: October 25, 2007, 02:15:38 AM »
That's correct. Normally a dot means match any character. It's basically a ? in the wildcard setup. (Actually, the wildcard patterns are translated to regular expressions anyway, so ? become plain old ., and * becomes .*)

BTW, is PasswordMaker checking all possible characters in the wildcards to make sure a regex pattern doesn't screw things up too much?
"I'm not drunk, just sleep deprived."

Offline tanstaafl

  • God Member
  • ******
  • Posts: 1363
Re: Pattern Example incorrect?
« Reply #4 on: October 25, 2007, 11:21:03 AM »
That's correct. Normally a dot means match any character. It's basically a ? in the wildcard setup. (Actually, the wildcard patterns are translated to regular expressions anyway, so ? become plain old ., and * becomes .*)

So, you are confirming that the example in the PWM dialog is wrong?

Quote
BTW, is PasswordMaker checking all possible characters in the wildcards to make sure a regex pattern doesn't screw things up too much?

? Can you elaborate on what you mean? A wildcard is any character - so what is there to check?

Offline Miquel 'Fire' Burns

  • Administrator
  • *****
  • Posts: 1157
  • Programmer
Re: Pattern Example incorrect?
« Reply #5 on: October 26, 2007, 01:06:50 AM »
If the regular expression were to be expressed as a wildcard (and ignoring that it allows both http and https, just http) it would be this: http://mail.yahoo.com/*

But if you remove the escaping of the dots, then it would be: http://mail?yahoo?com/*

See what I mean?
"I'm not drunk, just sleep deprived."

Offline Eric H. Jung

  • grimholtz
  • Administrator
  • *****
  • Posts: 3353
Re: Pattern Example incorrect?
« Reply #6 on: October 26, 2007, 01:13:33 AM »
Tanstaalf, when you find a spare 30 minutes just read a regexp tutorial. That's all it takes. Print it out and read during your commute. You definitely have the skills to grok it.

marr

  • Guest
Re: Pattern Example incorrect?
« Reply #7 on: February 12, 2008, 06:53:20 PM »
Why the last slash in the regexp expression must be escaped, but the doubleslashes at the beginning are not?

Offline Eric H. Jung

  • grimholtz
  • Administrator
  • *****
  • Posts: 3353
Re: Pattern Example incorrect?
« Reply #8 on: February 12, 2008, 07:35:54 PM »
Why the last slash in the regexp expression must be escaped, but the doubleslashes at the beginning are not?
They all should be escaped. Where are you looking?

Offline dschwartfeger

  • Normal Members
  • *
  • Posts: 8
Re: Pattern Example incorrect?
« Reply #9 on: May 07, 2008, 09:08:41 PM »
Why the last slash in the regexp expression must be escaped, but the doubleslashes at the beginning are not?
They all should be escaped. Where are you looking?

I think he's referring to the "add/edit pattern window in the extension" as shown by tanstaafl in the message above

it shows https?://mail\.yahoo\.com\/.* but should be https?:\/\/mail\.yahoo\.com\/.* I think

Offline Miquel 'Fire' Burns

  • Administrator
  • *****
  • Posts: 1157
  • Programmer
Re: Pattern Example incorrect?
« Reply #10 on: May 08, 2008, 01:11:16 AM »
I'm not sure if the slashes need to be escaped in the first place actually.

[edit] I should clarify that a bit. The way you define regular expressions in JavaScript (At least with how it used in PasswordMaker) does not use '/' to surround the epression. And since slashes have no meaning when they're not use to surround the expression, there's no need to escape them. (Also, it's possible to use other characters. When I make regular expressions at work that deal with urls, I use ~ or something similar)
« Last Edit: May 08, 2008, 01:20:25 AM by Miquel 'Fire' Burns »
"I'm not drunk, just sleep deprived."

Offline Eric H. Jung

  • grimholtz
  • Administrator
  • *****
  • Posts: 3353
Re: Pattern Example incorrect?
« Reply #11 on: May 08, 2008, 03:01:24 AM »
Forward slash is not a special character in Javascript regular expressions, so it doesn't need to be escaped. Perhaps you're thinking of backslashes.

Offline Miquel 'Fire' Burns

  • Administrator
  • *****
  • Posts: 1157
  • Programmer
Re: Pattern Example incorrect?
« Reply #12 on: May 08, 2008, 04:03:08 AM »
There's a forward slash that is escaped in the example for PasswordMaker. That appears to be causing some recent confusion right now.
"I'm not drunk, just sleep deprived."

Offline dschwartfeger

  • Normal Members
  • *
  • Posts: 8
Re: Pattern Example incorrect?
« Reply #13 on: May 10, 2008, 10:51:17 PM »
There's a forward slash that is escaped in the example for PasswordMaker. That appears to be causing some recent confusion right now.

Yes the example shows https?://mail\.yahoo\.com\/.*

I was thinking of perl regular expressions!?? Should have realized they would be Javascript! The example should perhaps be 'https?://mail\.yahoo\.com/.*' i.e. the last / is not escaped.

Does the documentation/help mention that the regular expressions should be Javascript ones? I find many programs specify they support regular expression but don't specify what kind. This is rather annoying as there are many variations and one never knows what is going to work & what isn't. Regular expressions can be hard enough to think through even if one is sure of what is supported!

In the case of Passwordmaker I want to be fairly sure they are correct so I don't match phishing sites for example.

Offline dschwartfeger

  • Normal Members
  • *
  • Posts: 8
Re: Pattern Example incorrect?
« Reply #14 on: May 10, 2008, 11:32:00 PM »
I have just read through some more of the Advanced usage wiki and see that it does give good documentation of the type of regexps supported! Well done whoever wrote it.

I think the example mentioned above should still be changed to clear up any confusion it may cause.

PasswordMaker Forums

Re: Pattern Example incorrect?
« Reply #14 on: May 10, 2008, 11:32:00 PM »