Jump to content

Recommended Posts

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
Posted

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.

Posted

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.

Posted

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.
Posted

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.

  • 4 weeks later...
Posted

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

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
  • Recently Browsing   0 members

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