Jump to content

StringRegExp Question


Go to solution Solved by jchd,

Recommended Posts

I'm really new to RegEx, I'm not sure what I'm doing :)

I'd like to filter the following:

- Starts with $ letter

- next is unknown char, unknown length

- until one of the following was found: SPACE, equation, comma, @CR, @LF, @CRLF, @TAB, [ letter

So I tried the following:

$1 = StringRegExp($str, '\$*[\h\n\r\t\=,[]', 3)

1st:  Start with $

2nd: Goes on with *

3rd:  Next letter is a group of the [ ... ] chars.

I tested and it returns tons of uncorrect results.

Could you help me with it?

Edited by Unc3nZureD
Link to comment
Share on other sites

CiVQ,

your character class is incomplete wrt the OP expectations.

$1 = StringRegExp($str, '\$(.*?)[\h\n\r\t\=,[]', 3)

* by itself is meaningless: it only means "zero or more of the preceding element".

EDIT: true, we have no clue as to what the OP wants captured, or whether he needs a boolean answer (match/no match).

Edited by jchd

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)

Link to comment
Share on other sites

The first post suggested that the leading $ must be grabbed

If not it needs grouping parentheses

$res = StringRegExp($str, '\$([^\s=,\[]+)', 3)

jc, the 3 in the regex also suggests that he wants to get plain string results

BTW does my expression match the OP's specifications in a satisfying way ? :)

Edited by mikell
Link to comment
Share on other sites

Thank you, all seem to work, can't figure out the differences yet, working on it to understand. It seems i did the * part wrong, it has to be (.*?) instead.

Yes, it's going to be a variable catcher for autoit :)

I found out that I need some further rules too, however I've got no idea how to implement it

- First is how to INCLUDE the $ sign too. (Not really important, however it could make my later code faster, since I don't have to add $ part all the time)

- Second is to filter out the following symbols too: ) ]     The problem is that it's a part of a regular expression, how can I make it the part of the filtering?

_____

I made this one from the uppers:

StringRegExp($str, '\$(.*?)[\s[)(,=]', 3)

The problem is that I don't know where and how could I add both [ and ] signs as last characters.

Edited by Unc3nZureD
Link to comment
Share on other sites

This expression

#Include <Array.au3>
$str = "$array[0] & $one, $two=1 & @crlf & ($three)  [$four] "
$res = StringRegExp($str, '\$[^\s=,\[\]\)]+', 3)
_ArrayDisplay($res)

means : "get all matches including a $ followed by one or more characters which are not h, CR, LF, =, comma, [ , ], ) "

It's a pretty way to put in the expression the trailing filter without getting it

Edit

Otherwise you can use an assertion (lookahead) like this

$res = StringRegExp($str, '(\$.+?)(?=[\s=,\[\]\)])', 3)

which means : "get a $ followed by one or more of any character, this group being followed by a space, a comma etc "

To get the $ you must include it in the capturing group

Edited by mikell
Link to comment
Share on other sites

  • Solution

That isn't going to end as easy as you seem to think of it. You can encounter valid but meaningless variable names in single end of line comments, in comment blocks, in strings; actual name may also appear in statements but without the $ sign (IsDeclared, Assign).

guinness has published a number of tools to dissect AutoIt code. You'd better look there first. Else a valid variable name (with $) matches the following pattern:

\$\w{1,4093}

and even then, I'm not sure you can use a variable name of that size (not going to test that either).

Edited by jchd

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)

Link to comment
Share on other sites

Holy sh1t, I tested that pattern with all my possible ideas, and it can detect everything. I can remove comments before detecting, and about assign:

If you assign a value to another which you won't use later in an expression, then it's useless, isn't it? Well, I'm trying to get as accurate as I just can. Thank's for the advices.

I'm trying to make a unique obfuscator, it'll be quite a hard work, but we need some challange to live :D

Edited by Unc3nZureD
Link to comment
Share on other sites

I whish you the best of luck, sincerely.

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)

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