kylomas Posted October 12, 2012 Share Posted October 12, 2012 (edited) Good Afternoon, Given the following string : 03/03/2010 1/12/2010 ee/ee/ee 10/3/1999 22/22/2222 11/11/11 \d\d/\d\d/\d\d\d\d will give me the two matches that I expect. Is there a way to return all lines that do NOT match the pattern? I've tried playng around with groups and the caret char to no avail, obviously. Thanks, kylomas Edited October 12, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jdelaney Posted October 12, 2012 Share Posted October 12, 2012 (edited) best i can do: $string = "03/03/2010" & @CRLF & _ "1/12/2010" & @CRLF & _ "ee/ee/ee" & @CRLF & _ "10/3/1999" & @CRLF & _ "22/22/2222" & @CRLF & _ "11/11/11" $adata = StringRegExp ( @CRLF & $string & @CRLF, "sd/d+/d+|d+/d/d+|sd+/d+/d{1,3}s|s[^ds]+.+/[^ds]+.+/[^ds]+.+s", 3 ) _ArrayDisplay ( $adata ) eaiser with stringregexp replace: $string = "03/03/2010" & @CRLF & _ "1/12/2010" & @CRLF & _ "ee/ee/ee" & @CRLF & _ "10/3/1999" & @CRLF & _ "22/22/2222" & @CRLF & _ "11/11/11" $string2 = StringRegExpReplace ( $string, "d{2,2}/d{2,2}/d{4,4}", "" ) $adata = StringSplit ( $string2, @CRLF, 2 ) For $i = UBound ( $adata ) - 1 To 0 Step -1 If StringLen ( $adata[$i] ) = 0 Then _ArrayDelete ( $adata, $i ) Next ConsoleWrite ( $string2) _ArrayDisplay ( $adata ) Edited October 12, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
kylomas Posted October 12, 2012 Author Share Posted October 12, 2012 jdelaney, Thanks for the prompt reply! If I understand you regexp correctly you are looking for all patterns that do not match the pattern that I want. This works for this example, however, I am auditing data prior to inclusion to a database and may not be able to id all possible BAD combinations. That is where my idea to return the NOT of matches came from. I want to review the data that does not match what I expect to make sure that I am anticipating all cases. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted October 12, 2012 Author Share Posted October 12, 2012 (edited) jdelaney,Sorry, missed your edit. I think that will work perfectly.kylomasedit: although I was hoping not to have to do this logically with arrays.*** WARNING ***The Surgeon General has determined that regular expression may be hazardous to your health. Edited October 12, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jdelaney Posted October 12, 2012 Share Posted October 12, 2012 I just added the arrays to get rid of those remnant carriage returns...couldn't get rid of them with the regexp. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
jchd Posted October 12, 2012 Share Posted October 12, 2012 If you need to sanitize individual data only, then use a simple StringRegExp with the required pattern and option 0. This should give you the green/red light you want. 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...
jchd Posted October 12, 2012 Share Posted October 12, 2012 @jdelaney, including a final s? in the pattern should work or am I missing something obvious? 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...
kylomas Posted October 12, 2012 Author Share Posted October 12, 2012 @jdelaney - thanks, works perfectly@jchd - thanks, I am doing some of that already. The case that I'm working on now is weeding out the myriad of ways that a date can be entered.I just started on this and it seemed that returning the NOT of an expression would be handy in many cases.kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jdelaney Posted October 12, 2012 Share Posted October 12, 2012 (edited) @jchd, i would expect that too even took into consideration that it was questionable s? (in case last record), no amount of manipulation could get rid of them, so i compromised on the array Edited October 12, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
kylomas Posted October 12, 2012 Author Share Posted October 12, 2012 Jdelaney, Your array method gets rid of the blank entries which makes the data easier to work with. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jdelaney Posted October 12, 2012 Share Posted October 12, 2012 duh, crlf is 2 characters, not 1...here is the way without the array: $string = "03/03/2010" & @CRLF & _ "1/12/2010" & @CRLF & _ "ee/ee/ee" & @CRLF & _ "10/3/1999" & @CRLF & _ "22/22/2222" & @CRLF & _ "11/11/11" $string2 = StringRegExpReplace ( $string, "d{2,2}/d{2,2}/d{4,4}[s]*", "" ) $adata = StringSplit ( $string2, @CRLF, 2 ) ConsoleWrite ( $string2) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
kylomas Posted October 12, 2012 Author Share Posted October 12, 2012 (edited) jdelaney,Thanks, perfect and almost instantaneos tested against a 50KB file. Inj retrospect I do need to see the blank entries as they indicate missing data.kylomasedit: brain fart from exposure to regexp Edited October 12, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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