ZeDMIN Posted January 23, 2006 Share Posted January 23, 2006 (edited) Hiya there,i tried to pull out some text from a file using RegExp. But unfortunately my pattern does not work, or at least not like i expected.Heres my test code (Expected to come out is "12:30:17 (588.62 KB/s)"):$result = StringRegExp("12:30:17 (588.62 KB/s) - random.bin saved [10485760/10485760]", "(\d\d.\d\d.\d\d[^)]*.)", 1) If (Not @error) And @Extended Then MsgBox(0, '', $result[0])The above does NOT work. I tracked down the problem to having a ")" in my "[^)]". Escaping this bracket "\)" does not work.But if i double escape the bracket "\\)" it will work:$result = StringRegExp("12:30:17 (588.62 KB/s) - random.bin saved [10485760/10485760]", "(\d\d.\d\d.\d\d[^\\)]*.)", 1) If (Not @error) And @Extended Then MsgBox(0, '', $result[0])Anyone else thinks this is a bug?Looking at the definition of regular expressions, my first code should be correct.Greetings,ZeD Edited January 23, 2006 by ZeDMIN Link to comment Share on other sites More sharing options...
w0uter Posted January 23, 2006 Share Posted January 23, 2006 $result = StringRegExp("12:30:17 (588.62 KB/s) - random.bin saved [10485760/10485760]", "(\d\d.\d\d.\d\d.*?\))", 1) If Not @error And @Extended Then MsgBox(0, '', $result[0]) dunno if it is a bug but why not just use this My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
Fur Posted January 23, 2006 Share Posted January 23, 2006 The parens are triggering the matching code that returns the matches in an array. If you need to match a paren, put the hex code for ( and ) in instead. Link to comment Share on other sites More sharing options...
ZeDMIN Posted January 24, 2006 Author Share Posted January 24, 2006 i guess both of these workarounds would work. it's just that this syntax works in other programs which use regular expressions. so it is nevertheless a bug. but thanks for those two ideas, i guess i will use the one with the hexcode, because i had somewhen already a problem with a similar expression like wouter wrote. Link to comment Share on other sites More sharing options...
ZeDMIN Posted January 24, 2006 Author Share Posted January 24, 2006 DOH! [^\041] doesn't work also. so i have to take wouters workaround. Link to comment Share on other sites More sharing options...
Fur Posted January 24, 2006 Share Posted January 24, 2006 DOH! [^\041] doesn't work also. so i have to take wouters workaround. Sorry, I wasn't clearer. You need to use \0040 and \0041. Link to comment Share on other sites More sharing options...
ZeDMIN Posted January 24, 2006 Author Share Posted January 24, 2006 i tried that too. same problem. i guess it converts hex and decimal codes back to the original character. so theres no difference what you take. Link to comment Share on other sites More sharing options...
neogia Posted February 18, 2006 Share Posted February 18, 2006 Or you could make it even simpler. If I'm correct in assuming you're reading this type of line over and over, then$result = StringRegExp("12:30:17 (588.62 KB/s) - random.bin saved [10485760/10485760]", "(.+)(?: -)", 1)should work just fine.I do think the \) not working is a bug though. Because I just used the same thing on an ( here. I'd submit it as a bug. [u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia 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