Sign in to follow this  
Followers 0
ZeDMIN

StringRegExp bug?

8 posts in this topic

#1 ·  Posted (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 by ZeDMIN

Share this post


Link to post
Share on other sites



$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 :lmao:


My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

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.

Share this post


Link to post
Share on other sites

DOH! [^\041] doesn't work also. so i have to take wouters workaround.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0