Unc3nZureD Posted January 18, 2014 Share Posted January 18, 2014 (edited) 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 January 18, 2014 by Unc3nZureD Link to comment Share on other sites More sharing options...
CiVQ Posted January 18, 2014 Share Posted January 18, 2014 (edited) Try this: $1 = StringRegExp($str, '\$(.*?)[\s[]', 3) (non-greedy matching) BR. CiV. Edited some typo. Edited January 18, 2014 by CiVQ I know that my code is ugly. But it works. Mostly. Link to comment Share on other sites More sharing options...
mikell Posted January 18, 2014 Share Posted January 18, 2014 (edited) Hmm looks like a variable check Try this #Include <Array.au3> $str = "$array[0] & $one, $two=1 & @crlf & $three" $res = StringRegExp($str, '\$[^\s=,\[]+', 3) _ArrayDisplay($res) Edited January 18, 2014 by mikell Unc3nZureD 1 Link to comment Share on other sites More sharing options...
jchd Posted January 18, 2014 Share Posted January 18, 2014 (edited) 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 January 18, 2014 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
CiVQ Posted January 18, 2014 Share Posted January 18, 2014 @jchd: What do you mean? * means what you wrote. Did I miss the leading dot? I know that my code is ugly. But it works. Mostly. Link to comment Share on other sites More sharing options...
mikell Posted January 18, 2014 Share Posted January 18, 2014 (edited) 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 January 18, 2014 by mikell Unc3nZureD 1 Link to comment Share on other sites More sharing options...
Unc3nZureD Posted January 18, 2014 Author Share Posted January 18, 2014 (edited) 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 January 18, 2014 by Unc3nZureD Link to comment Share on other sites More sharing options...
mikell Posted January 18, 2014 Share Posted January 18, 2014 (edited) 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 January 18, 2014 by mikell Unc3nZureD 1 Link to comment Share on other sites More sharing options...
Solution jchd Posted January 18, 2014 Solution Share Posted January 18, 2014 (edited) 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 January 18, 2014 by jchd Unc3nZureD 1 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Unc3nZureD Posted January 18, 2014 Author Share Posted January 18, 2014 (edited) 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 Edited January 18, 2014 by Unc3nZureD Link to comment Share on other sites More sharing options...
mikell Posted January 18, 2014 Share Posted January 18, 2014 A good way to learn regex though Link to comment Share on other sites More sharing options...
jchd Posted January 19, 2014 Share Posted January 19, 2014 I whish you the best of luck, sincerely. Unc3nZureD 1 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now