Jump to content
Sign in to follow this  
Klaatu

Bad pattern for StringRegExp?

Recommended Posts

Klaatu

Using AutoIt 3.2.8.1, I'm running a script that worked fine with (if I remember right) 3.2.4.9, but fails now.

I think I've narrowed down the problem to an RE that worked fine before but 3.2.8.1 indicates the pattern is bad (@Error set to 2). Here's the pattern string: '(10\.(64\.[:digit:]{1,3}|79\.12)\.[:digit:]{1,3})'. If you can't guess from this I'm trying to match an IP address to this pattern (ie, '10.64.192.134'). StringRegExp is setting @Extended to 11, pointing to the first '[' char in the string.

Can someone tell me why StringRegExp is reporting a bad pattern? Did something change in the pattern syntax that would make this pattern which worked with 3.2.4.9 now invalid under 3.2.8.1?


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites
SmOke_N

Using AutoIt 3.2.8.1, I'm running a script that worked fine with (if I remember right) 3.2.4.9, but fails now.

I think I've narrowed down the problem to an RE that worked fine before but 3.2.8.1 indicates the pattern is bad (@Error set to 2). Here's the pattern string: '(10\.(64\.[:digit:]{1,3}|79\.12)\.[:digit:]{1,3})'. If you can't guess from this I'm trying to match an IP address to this pattern (ie, '10.64.192.134'). StringRegExp is setting @Extended to 11, pointing to the first '[' char in the string.

Can someone tell me why StringRegExp is reporting a bad pattern? Did something change in the pattern syntax that would make this pattern which worked with 3.2.4.9 now invalid under 3.2.8.1?

StringRegExp uses the PCRE engine... if something is failing in AutoIt it's failing in that engine, you might want to test your patterns in there to see if they are compatible.

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.

Share this post


Link to post
Share on other sites
Siao

This definitely doesn't work with 3.2.4.9, because the pattern is definitely incorrect.

[:digit:] should be [[:digit:]]


"be smart, drink your wine"

Share this post


Link to post
Share on other sites
PsaltyDS

StringRegExp uses the PCRE engine... if something is failing in AutoIt it's failing in that engine, you might want to test your patterns in there to see if they are compatible.

OMG!! I beat SmOke_N to a RegExp answer! Wohoo! Party time!

:):lol::P:lol::):lol::D:lol::lol::lol:

..ahem.

You have to double up the square brackets around the character class:

$sString = '11.11.11.11'
$sPatt = '(10\.(64\.[[:digit:]]{1,3}|79\.12)\.[[:digit:]]{1,3})'
$RET = StringRegExp($sString, $sPatt, 0)
ConsoleWrite("Debug:  $Ret = " & $RET & @LF & "@error = " & @error & @CRLf & "@extended = " & @extended & @LF)

$sString = "10.64.23.33"
$RET = StringRegExp($sString, $sPatt, 0)
ConsoleWrite("Debug:  $Ret = " & $RET & @LF & "@error = " & @error & @CRLf & "@extended = " & @extended & @LF)

:lol:

Edit: Rats. Took so long typing up a demo the Siao-bot beat me to it... that's OK, as long as we got one past SmOke_N! <_<

Edited by PsaltyDS

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

Share this post


Link to post
Share on other sites
Klaatu

This definitely doesn't work with 3.2.4.9, because the pattern is definitely incorrect.

[:digit:] should be [[:digit:]]

I'll give that a try, but the AutoIt Help file doesn't mention anything about the character classes using two bracket characters to define them.

It might not have been 3.2.4.9 that I was using before, but the above string did work correctly with whatever version I was using before I upgraded to 3.2.8.1. Possibly I was using 3.2.0.1 then, but anyway it definitely worked before.

Anyway, thanks for the help, even if it doesn't seem to jive with the AutoIt's own help file.


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites
PsaltyDS

I'll give that a try, but the AutoIt Help file doesn't mention anything about the character classes using two bracket characters to define them.

It might not have been 3.2.4.9 that I was using before, but the above string did work correctly with whatever version I was using before I upgraded to 3.2.8.1. Possibly I was using 3.2.0.1 then, but anyway it definitely worked before.

Anyway, thanks for the help, even if it doesn't seem to jive with the AutoIt's own help file.

It's not completely obvious, but it is in there in the table under "[:class:]":

... So [0-9] is equivalent to [[:digit:]].

The thing is, the class is defined by only one set of square brackets, the outer brackets are enclosing the 'set'.

In the case of this set, there is only one class used: "[[:digit:]]".

Suppose you want to match a single digit or a single lower case letter, but NOT an upper case letter: "[[:digit:][:lower:]]"

See? The character classes are in a set of square brackets, and then another set encloses them to indicate the set.

<_<


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

Share this post


Link to post
Share on other sites
Klaatu

It's not completely obvious, but it is in there in the table under "[:class:]":

The thing is, the class is defined by only one set of square brackets, the outer brackets are enclosing the 'set'.

In the case of this set, there is only one class used: "[[:digit:]]".

Not directed at you, Old Bird, more thinking out loud here, but looking at AutoIt's page on StringRegExp under the "Matching Characters" table it has this:

[^:class:] Match any character not in the class, but only if the first character.

That doesn't actually work if I'm not mistaken. You don't put '[[^:digit:]]' to match a non-digit, which just by looking at the entry above that one might assume. The correct way is of course '[^[:digit:]]' but one would never know that by the way the help is written.

Anyway, it just looks to me like that part of the help is badly worded or organized. At a minimum it's confusing, even to someone who's relatively familiar with REs.


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites
PsaltyDS

Not directed at you, Old Bird, more thinking out loud here, but looking at AutoIt's page on StringRegExp under the "Matching Characters" table it has this:

That doesn't actually work if I'm not mistaken. You don't put '[[^:digit:]]' to match a non-digit, which just by looking at the entry above that one might assume. The correct way is of course '[^[:digit:]]' but one would never know that by the way the help is written.

Anyway, it just looks to me like that part of the help is badly worded or organized. At a minimum it's confusing, even to someone who's relatively familiar with REs.

I think the line there is that RE is too big a topic for the help file. The real answer is AutoIt implements the PCRE standard library deep in its little C++ heart. So for real help Google or Wiki the PCRE engine. Trying to make the AutoIt help file a good complete guide to PCRE would double its size just for that function. This post has a link to the POSIX Character Class Definition. That's where I found it AFTER figuring this out with trial-and-lots-of-error.

<_<


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

Share this post


Link to post
Share on other sites
SmOke_N

I think the line there is that RE is too big a topic for the help file. The real answer is AutoIt implements the PCRE standard library deep in its little C++ heart. So for real help Google or Wiki the PCRE engine. Trying to make the AutoIt help file a good complete guide to PCRE would double its size just for that function. This post has a link to the POSIX Character Class Definition. That's where I found it AFTER figuring this out with trial-and-lots-of-error.

:)

Well, I'll agree with that for sure... which is why I referenced him outside AutoIt to look at his issue to begin with <_<

But at the same time, he's right, there should be better documentation, but I know I don't have the patience or the time to write it. The documentation you read (most of it anyway) is still from the old type of RegExp engine we used to use.


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.

Share this post


Link to post
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
Sign in to follow this  

×