Jump to content

Autoit and Regex


Orca
 Share

Recommended Posts

I kind of know Regex from PHP and REGULAR Regular Expressions. The kind of stuff like /^[^[]]/ or /^[a-zA-Z]|^[1-9]/

Not this [aeiou] crap... That was the example in the CHM help file. And an example that gave NO reference how to USE Regex inside autoit, only how to administer it... The example is of some dialog boxes that you put in your own regex and it tells you if they work... But not how to write your own regex in autoit.... Some help please?

How would I confirm a line followed the following syntax?

["%s"] = {

},

%s = {

}

["%s"] = %s,

It has to be able to differentiate between each of those lines as well... Maybe if documentation was better I could figure this out on my own... (Now goes and uses search button! ;) Post then search, learn then edit the post to solved :-D)

I AM ORCA!! A VERY POWERFUL WHALE!!!

Link to comment
Share on other sites

  • Moderators

Maybe if documentation was better I could figure this out on my own... (Now goes and uses search button! ;) Post then search, learn then edit the post to solved :-D)

Glad your searching on your own... and hope that the 'documentaton better' statement was tongue and cheek.

GL

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

It would be acceptable to assume that anyone wanting to use these functions already has a grasp on regexes. A full-blown tutorial isn't really necessary because they are sprayed all over the 'Net.

How would I confirm a line followed the following syntax?

I'm confused by what you wrote after that (particularly the curly braces -- should they contain content?). Could you please post some examples of what would ideally be matched and what wouldn't?

P.S. [aeiou] is valid regex talk...?

P.S. /^[a-zA-Z]|^[1-9]/ == /^[a-zA-Z1-9]/.

Edited by LxP
Link to comment
Share on other sites

LxP

That is what I know regex to be! /^[^[]]/ -> Anything that is not nothing

%s signifies where a string of letters, numbers, symbols, and in general any ASCII character will be at just about any length from 1 char to 999 chars... It just needs to match string, The rest of the text is what is hard coded in each line, the %s is the portion of the line that varies... If you can understand what I mean...

0
1
2   Key0 = {
3       ["User0"] = {
4           ["value1"] = 723330,
5       },
6       ["User1"] = {
7           ["value2"] = 303651,
8       },
9       ["User2"] = {
10          ["money3"] = 0,
11      },
12  }

There is a file I'm parsing with line numbers on the left. The key here is I will recieve one of those lines each check and must determine which kind of the 4 different formats it is.

The things I had in my first post would be the 4 different types.

Edited by SiC_Goat

I AM ORCA!! A VERY POWERFUL WHALE!!!

Link to comment
Share on other sites

That is what I know regex to be! \^[^[]]\ -> Anything that is not nothing

Can also be done as /.+/ (match one or more of any character).

%s signifies where a string of letters, numbers, symbols, and in general any ASCII character will be at just about any length from 1 char to 999 chars... It just needs to match string, The rest of the text is what is hard coded in each line, the %s is the portion of the line that varies... If you can understand what I mean...

Hmm... this kind of processing looks like it might be done best via recursion...

If you're just checking for validity on a line-by-line basis (i.e. not checking each entity completely), you could probably get away with a regular expression along the lines of:

/^\}\,?$|^(\[\")?.*(\"\])?[\t ]*=[\t ]*.*$/

I know that that's not ideal but hopefully it will move you in the right direction.
Link to comment
Share on other sites

Unfortunatly Autoit doesn't use regular regex... What I found was that you cannot escape the [ ] " characters, when I used the \0### ACSII code for [" and "] it worked, also instead of using %s it required (.*)

This is the actual code I used

$ret = StringRegExp('["name"] = {', "\091\034(.*)\034\093", 1)

And $ret[0] would be returned as "name"

I AM ORCA!! A VERY POWERFUL WHALE!!!

Link to comment
Share on other sites

Looks like what you're used to are Perl Compatible Regular Expressions (PCRE). If I understand correctly, AutoIt's regular expressions seem almost more POSIX based (although I'm not sure, seems AutoIt's RegEx is more powerful than the POSIX stuff).

Anyway, your %s to match any alphanumeric character can be replaced with \A (it's even in the help file). And as near as I can tell, my brackets are escaping just fine.

Take this code for instance, it should do exactly what yours does.

$string = '["Parameter"]'
$pattern = '\["(\A+)"\]'
$return = StringRegExp($string, $pattern, 1)

You're right about the StringRegExp example though. What's there is good, but a bit complex.

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...