Sign in to follow this  
Followers 0
Newb

Still problem with RegExps in autoit....

7 posts in this topic

#1 ·  Posted (edited)

Hi all!

IN BRIEF

Have this string

239,827 and 292,928,398 and 92,365 but also 293,302,320

but not 212,323,443,555,645 or 30,34 or also 392,33 and not even 034,392,233

Want a regexp that catches the first 4 numbers (commas included) along with all numbers up to 999,999,999.

this is what i came up with

(^[1-9]\d{0,2}(,?\d{0,3}){0,2})

but it does catch only the first one.

DETAILED VERSION

The engine that runs autoit regexps is bugging me...

I have no problem developing regexes with Perl or this http://www.perlfect.com/articles/regextutor.shtml which uses a perl engine...

but when it comes to autoit there is always some kind of problem.

I need to catch numbers with comma inbetween in the format shown below (they must go from 0 to 999,999,999 with the comma and can't have a 0 in the fist group of 3 numbers)

The test string is:

239,827 and 292,928,398 and 92,365 but also 293,302,320

but not 212,323,443,555,645 or 30,34 or also 392,33 and not even 034,392,233

and the regexp i managed to write is:

(^[1-9]\d{0,2}(,?\d{0,3}))

So the results are limited to this

[0]= 239,827

[1]=,827

whil i want it to catch these numbers

239,827 and 292,928,398 and 92,365 but also 293,302,320

and not the others.

The problem in this code is that i don't know how to make it repeat the 3 digits after a comma.

I thought about this:

(^[1-9]\d{0,2}(,?\d{0,3}){0,2})

But still autoit catches only this:

[0]= 239,827

[1]=

Here's some quick code for testing if you need:

#include <Array.au3>
$mu="239,827 and 292,928,398 and 92,365"
$mud=StringRegExp($mu,"(^[1-9]\d{0,2}(,?\d{0,3}){0,2})",3)
_ArrayDisplay($mud,"jjj")

How can I solve? Thanks

Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites



Something like this: ?

#include <Array.au3>
$mu=" 239,827 and 292,928,398 and 92,365 but not 212,323,443,555,645 or 30,34 or also 392,33 and not even 034,392,233"
$mud=StringRegExp($mu,"[^d,]{1}([1-9]{1,3}(?:,d{3}){1,2})[^d,]",3)
_ArrayDisplay($mud,"jjj")

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yeah, that works nice. THANK YOU ;)

Can you help me to understand it please?

So

[^d,]{1}

what does this do? From how i read it is that the first charachter should NOT be any SINGLE number (0-9) or a comma.

But test takes even 0,232,000. Which is not correct. I can't really understand what is for in that expression please explane me i've gone mad trying to get it lol

([1-9]{1,3}

This catches any number repeated between 1 and 3 times which falls under the category [1-9]

Moreover this must be corrected into

([0-9]{1,3} otherwise numbers like 1,000,000 will not be taken.

(?:,d{3}){1,2})[^d,]

Here's another mistery....

First, does this do another separate check or it checks numbers right after the previous checks? Or in other words the one before and this one are separate checks (like one checks the number I want and this one checks the numbers I don't want)???

About the expression:

?: in help it'r called Non-capturing group. So as reading the help, everything after until the closed parenthesis will not be taken/matched in my result array, right???

after, i read that this expression will not consider any number between 0-9 repeated 3 times (and again {1,2} repeated between 1 or 2 times) but a number like 000,233,323 it's taken as valid, as well as 212,212,333 (which is a regular number i'd accept) and again I don't know what it does at the end.... please explain me...

Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites

BTW, the engine AutoIt uses for regular expression is PCRE (Perl-Compatible Regular Expression). See http://www.pcre.org/

Compatibility with Perl regexpes is high, very high!


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks jchd, I was already aware about the existance of that document, and I did read it a bit some time ago. It was way too extended and complicated so I dropped it, but anyway, I ended up findind a solution anyay, mainly thanks to Jos example regex, which almost does all the works but needed to be perfected to work well, and to work well with my needs too.

At the moment, the best I could do is this:

[^,0d][1-9]{1,3}(?:,[^d]?d{3}){0,2}[^d]

Which does the thing I need pretty good (It's still not perfect, but whatever, it does the job pretty well!)

Thanks to all for the support and the help. Finally I can help other users too after much time asking, but sometimes, meh, I still need to ask... ;)

Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites

No problem, there is always somebody willing to help here.

BTW, the complete documentation for PCRE comes with the source code tarball. Note that AutoIt PCRE could be a few releases back, but that only impacts fairly advanced features or dark corners.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Good, the one in use now works anyway, but in a slightly different way than pure PERL parsers. (actually i find it a bit harder, but whatever, autoit is ALL awesome so I forgive you ;):D )

Thanks and happy Easter to all of you (if you even celebrate it :) )


I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

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  
Followers 0