Jump to content

Regular Expression Testing


Nutster
 Share

Recommended Posts

  • Replies 138
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

So what do the others do instead?  Besides, I have been creating my own original implementation here, so what enhancements we want, we can add.  Yes, I am trying to stay as close to other implementations as I can, but we need to make this our own. :idiot:

<{POST_SNAPBACK}>

I guess I'm used the search-and-replace reg expression support in editors such as TextPad and SciTE, so anything that would help accomplish that would be good.

By the way, I think ^ and $ are missing from the docs.

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

  • Administrators

Nope, but it is on the RegExp to do list that I plan to work on in the new year.  I want to get array initializing done first, though.  Maybe a debug version after that.

My original name was that, but it made some of the related commands (no longer present) have huge names.  I changed the name and stuck it in the middle of the registry commands in the function list.  I do not have a problem if Jon wants to rename it.

I'd quite like the regex replace function to be the next priority. It's one regex function that I can actually imagine using :idiot: Seeing how much it gets used it PHP ( like on every other line) has made me see a lot of potential for it.

The Dim thing and debug things are just nice-to-haves IMHO.

Link to comment
Share on other sites

I guess I'm used the search-and-replace reg expression support in editors such as TextPad and SciTE, so anything that would help accomplish that would be good.

By the way, I think ^ and $ are missing from the docs.

<{POST_SNAPBACK}>

Oops. I know that ^ and $ are working, but I guess I left the documentation incomplete. Could someone fix the docs for me as I will not be working on this for at least a week. Ask Jon how much I enjoy documenting my work. :D

I'd quite like the regex replace function to be the next priority.  It's one regex function that I can actually imagine using :idiot:  Seeing how much it gets used it PHP ( like on every other line) has made me see a lot of potential for it.

The Dim thing and debug things are just nice-to-haves IMHO.

<{POST_SNAPBACK}>

I can do that. Flag for global replacement. I guess I could add that flag for RegExp as well, instead of (or maybe as well as) ! on a group to supress reporting it in the array.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

Well, hello everybody.

First of all thank you for AutoIt v3, it's a great tool I use with real pleasure :idiot: .

As I used to develop Perl scripts, I'm particularly interested in regular expression use. So, as soon as you included regexp functions, I happened to test and use them.

You recent changes made me rewrite my matching error management but that's the bill to pay to use the last (beta in fact, I know) release of AutoIt v3. But the main points of this message are:

1 - Some of my regular expressions are still matched but even if my pattern contain a group, I can't retrieve anything, my $aMatches variable never happen to be an array whereas more simple test show me that your RegExp function works the way you say.

2 - From the beginning, I'm asking me why you didn't choose to use any already released C++ library to offer regular expression management... (such as this one for instance)

For 1), I'm still working on it and I think/hope I'll make this work. But 2) is a real question to you...

A good program computing A into B is mostly one that won't crash in all the other cases...
Link to comment
Share on other sites

  • Administrators

2 - From the beginning, I'm asking me why you didn't choose to use any already released C++ library to offer regular expression management... (such as this one for instance)

Lots of reasons. A few are

- It's massive (the library above looks to be about 2MB alone). Lots of stuff in Autoit is custom written purely for size reasons. I could have used zlib for aut2exe compression but even that is too big for what we need. Instead I wrote a 2-3KB compression routine instead.

- At the moment all code in AutoIt has been custom written for AutoIt. I like this. I don't intend to use 3rd party code unless there is no alternative. If nothing else it makes licensing decisions more simple.

Link to comment
Share on other sites

Thanks for your answer: things get clearer this way.

As a consequence, I'll help you as much as I can on this particular regexp subject.

PS: I fully agree regarding the size aspect...

A good program computing A into B is mostly one that won't crash in all the other cases...
Link to comment
Share on other sites

Well, hello everybody.

You recent changes made me rewrite my matching error management but that's the bill to pay to use the last (beta in fact, I know) release of AutoIt v3. But the main points of this message are:

1 - Some of my regular expressions are still matched but even if my pattern contain a group, I can't retrieve anything, my $aMatches variable never happen to be an array whereas more simple test show me that your RegExp function works the way you say.

<{POST_SNAPBACK}>

Can you give me some specific examples that do not work the way you expect? I will look at them next week when I get home.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

I plan on adding a flag to the call of StringRegExp (the new name) to indicate whether the return value should be the array of group text, or just a true/false and to indicate whether to do a global search or not.

Flag:

0 - Return true/false

1 - Return array of first set of matching groups.

2 - Global search, but return true or false. Slower, but same behaviour as 0.

3 - Return array of all matching groups. Note that one set does not start before the previous one ends.

What do people think?

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

[..]

Flag:

0 - Return true/false

1 - Return array of first set of matching groups.

2 - Global search, but return true or false.  Slower, but same behaviour as 0.

3 - Return array of all matching groups.  Note that one set does not start before the previous one ends.

What do people think?

<{POST_SNAPBACK}>

Sounds good: but what is a "Global Search" (2)? And can you expand a bit on (3) please - does this mean when you have nested groups? Edited by trids
Link to comment
Share on other sites

  • Administrators

I plan on adding a flag to the call of StringRegExp (the new name) to indicate whether the return value should be the array of group text, or just a true/false and to indicate whether to do a global search or not.

Flag:

0 - Return true/false

1 - Return array of first set of matching groups.

2 - Global search, but return true or false.  Slower, but same behaviour as 0.

3 - Return array of all matching groups.  Note that one set does not start before the previous one ends.

What do people think?

Yeah, with the default (and if no flag is present) of just a true/false. I might try and get win titles working with regexps as well, that would be pretty cool.

(from the code it looks like I just pass NULL for the variant pointer to not bother with the array return?)

Link to comment
Share on other sites

Sounds good: but what is a "Global Search" (2)? And can you expand a bit on (3) please - does this mean when you have nested groups?

<{POST_SNAPBACK}>

Ok there are two flags: Array return (1 - return array of strings with status in @Error, 0 - return true false, @error = 0 or 2 [screwed up pattern]) and Global search (2 - global search for matches, 0 - single search for matches). Add together the flags you want. Due to this distinction, the global search and the single search will both succeed or fail with the same strings, but the global search takes longer. Do not bother using global search with just a true/false return.

Yeah, with the default (and if no flag is present) of just a true/false.  I might try and get win titles working with regexps as well, that would be pretty cool. 

(from the code it looks like I just pass NULL for the variant pointer to not bother with the array return?)

<{POST_SNAPBACK}>

WinGetTitle? Very Cool! Yet another option for that function. :idiot:

As far as calling CRegExp::compare(), yeah, just give it a NULL in the array pointer to not store anything. Instead of returning the array, return the result of the compare() call. This could screw up my implentation of back-referencing, but I will fix it when I add the feature.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

I think I have it now: an array-return (flag=1) provides all the groups in the first match of a pattern; and a global array-return (flag=1+2) provides all the groups wherever the pattern matches. So a flag=3 returns a 2D array .. right?

:idiot: .. I must have been very dof yesterday!

Link to comment
Share on other sites

I think I have it now: an array-return (flag=1) provides all the groups in the first match of a pattern; and a global array-return (flag=1+2)  provides all the groups wherever the pattern matches. So a flag=3 returns a 2D array .. right?

<{POST_SNAPBACK}>

flag = 3 = 1 + 2. It returns nothing at the moment. :idiot: I am planning to just tack onto the end of the existing 1-dimensional array with the global search group matches (a lot easier).

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

flag = 3 = 1 + 2.  It returns nothing at the moment.  ;)  I am planning to just tack onto the end of the existing 1-dimensional array with the global search group matches (a lot easier).

<{POST_SNAPBACK}>

Easier :idiot: ? Wouldn't it be easier to interpret the results from a 2D array? Imagine a scenario where you have some text and you want the last IP address that appears in it.

Sure, you can use an offset to interpret it as a 2D array .. but the last time I did this was when I was writing games for a Commmodore-64 :D

I guess if it's lots of (internal) code to provide a 2D array, then we can always simulate it with a UDF .. we can document the results as a "retro-array" :lol:

Link to comment
Share on other sites

  • 2 weeks later...

David, how does one go about using the {x,y} feature? I've tried this but it doesn't work:

$string = 12
$res = StringRegExp($string, "([0-9]{2})")
If Not @error Then MsgBox(4096, "", $res[0])

It doesn't work, however.

Link to comment
Share on other sites

Might be a bug because the following works:

$string = 12

$res = StringRegExp($string, "([0-9]{2,2})")

If Not @error Then MsgBox(4096, "", $res[0])

<{POST_SNAPBACK}>

Thanks, I didn't think to try that one. I couldn't get any combination of things to work, but you're right, that method does.
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...