LocationUnknown Posted April 24, 2010 Share Posted April 24, 2010 First of all Hello ,I'm currently trying to use StringRegExp() to match numbers in a string.<----- THE DATA ($full) ------>Memory Processes Infected: 2 Memory Modules Infected: 0 Registry Keys Infected: 1 Registry Values Infected: 0 Registry Data Items Infected: 5 Folders Infected: 100 Files Infected: 3<----- THE CODE ------>$memory_num = StringRegExp($full, '(?: *.Processes.*? )([0-9]{1,200})', 2) $modules_num = StringRegExp($full, '(?: *.Modules.*? )([0-9]{1,200})', 2) $regkey_num = StringRegExp($full, '(?: *.Keys.*? )([0-9]{1,200})', 2) $regval_num = StringRegExp($full, '(?: *.Values.*? )([0-9]{1,200})', 2) $regdata_num = StringRegExp($full, '(?: *.Data.*? )([0-9]{1,200})', 2) $folders_num = StringRegExp($full, '(?:Folders.*?)([0-9]{1,200})', 2) $files_num = StringRegExp($full, '(?:Files.*? )([0-9]{1,200})', 2)I can read single digits fine but when it comes to "Folders Infected: 100". "1" is returned not "100" i have tried using $folders_num = StringRegExp($full, '(?:Folders.*?): (\d+)', 2)This still only returns "1"Can someone please be kind and understanding and explain to me what I'm doing wrong.Thanks Link to comment Share on other sites More sharing options...
martin Posted April 24, 2010 Share Posted April 24, 2010 First of all Hello , I'm currently trying to use StringRegExp() to match numbers in a string. <----- THE DATA ($full) ------> Memory Processes Infected: 2 Memory Modules Infected: 0 Registry Keys Infected: 1 Registry Values Infected: 0 Registry Data Items Infected: 5 Folders Infected: 100 Files Infected: 3 <----- THE CODE ------> $memory_num = StringRegExp($full, '(?: *.Processes.*? )([0-9]{1,200})', 2) $modules_num = StringRegExp($full, '(?: *.Modules.*? )([0-9]{1,200})', 2) $regkey_num = StringRegExp($full, '(?: *.Keys.*? )([0-9]{1,200})', 2) $regval_num = StringRegExp($full, '(?: *.Values.*? )([0-9]{1,200})', 2) $regdata_num = StringRegExp($full, '(?: *.Data.*? )([0-9]{1,200})', 2) $folders_num = StringRegExp($full, '(?:Folders.*?)([0-9]{1,200})', 2) $files_num = StringRegExp($full, '(?:Files.*? )([0-9]{1,200})', 2) I can read single digits fine but when it comes to "Folders Infected: 100". "1" is returned not "100" i have tried using $folders_num = StringRegExp($full, '(?:Folders.*?): (\d+)', 2) This still only returns "1" Can someone please be kind and understanding and explain to me what I'm doing wrong. Thanks I think $folders_num[1] will be 100 using StringRegExp($full, '(?:Folders.*?): (\d+)', 2) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
LocationUnknown Posted April 24, 2010 Author Share Posted April 24, 2010 Silly me, it was an issue with the way i was feeding the data into $full Thanks Link to comment Share on other sites More sharing options...
jchd Posted April 24, 2010 Share Posted April 24, 2010 Are you sure you're wanting to grab as many as 200 decimal digits? (Hint: probably not, and as shown by Martin, \d+ is better in your case.) Result is an array. Also you don't need the non capturing groups. But now you've got it. 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...
LocationUnknown Posted April 25, 2010 Author Share Posted April 25, 2010 Thanks jchd, i understand that ([0-9]{1,200}) declares a range between 1 - 200. Your right that \d+ is much more suitable in this situation where the value could be just about anything. I realize that StringRegExp generates an array and there is no need for individual variables to be defined . This site helped me out when using regular expression http://regexpal.com/.Cheers Link to comment Share on other sites More sharing options...
jchd Posted April 25, 2010 Share Posted April 25, 2010 i understand that ([0-9]{1,200}) declares a range between 1 - 200Yes, 200 ... DIGITS! A regexp quantifier as {x,y} applied to a metacharacter Z means Z repeated from x times to y times inclusive. So \d{1,200} means a string of at least 1 and up to 200 decimal digits. In general, regexp metacharacters don't look at content, but simply category. There is no interpretation of the successive characters matched or captured as a whole (here as an integer representation). Regexps are fairly formal. 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