Jump to content

Character class not working with regexp


 Share

Recommended Posts

Shouldn't this return 1?

ConsoleWrite(StringRegExp('hello', '[:alpha:]'))
Should be:

ConsoleWrite(StringRegExp('hello', '[[:alpha:]]'))

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Should be:

ConsoleWrite(StringRegExp('hello', '[[:alpha:]]'))

;)

YAY!! :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

That's it? That's been bugging me forever! That should be mentioned in the doc's cus the way it's presented in there I assumed I should just be able to go like StringRegExp('hello', '([:alpha:]+)') or whatever.

Thanks!

Smoke, are you YAY'ing because you couldn't get it to work either? (I'm hoping to save some of my dignity here) Or was I alone in my misunderstanding?

Link to comment
Share on other sites

That's it? That's been bugging me forever! That should be mentioned in the doc's cus the way it's presented in there I assumed I should just be able to go like StringRegExp('hello', '([:alpha:]+)') or whatever.

Thanks!

Smoke, are you YAY'ing because you couldn't get it to work either? (I'm hoping to save some of my dignity here) Or was I alone in my misunderstanding?

I wasn't clear on the rules requiring the extra square brackets. Here's one reference that kind of hints at it:

Perl supports the POSIX notation for character classes. This uses names enclosed by [: and :] within the enclosing square brackets. PCRE also supports this notation. For example,

[01[:alpha:]%]

matches "0", "1", any alphabetic character, or "%".

That kind of thing didn't really turn the light on for me, but after a lot of trial and error around it, I hit on the double brackets. AFTERWARDS, I searched for that patter and found a reference to that exact syntax:

Regular Expressions - User guide (scroll down to "POSIX Character Class Definitions"):

These are always used inside square brackets in the form [[:alnum:]] or combined as [[:digit:]a-d]

:)
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Smoke, are you YAY'ing because you couldn't get it to work either? (I'm hoping to save some of my dignity here) Or was I alone in my misunderstanding?

No, I knew it, I was Yaying PsaltyDS because he's repeatedly said he didn't understand RegExp's that well, and he found the solution for you.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

No, I knew it, I was Yaying PsaltyDS because he's repeatedly said he didn't understand RegExp's that well, and he found the solution for you.

...like when you cheer the slow kid who finally gets fractions.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...