Jump to content

StringRegExp bug?


ZeDMIN
 Share

Recommended Posts

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
Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

  • 4 weeks later...

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...