Jump to content

regular expression is not found in dictionary?


Go to solution Solved by SadBunny,

Recommended Posts

Posted (edited)

Can someone please say me what i'm missing here?

this little problem is driving me crazy!

i feel so stupid that i have to ask this but why does this script thinks that "=" doesn't exist inside the dictionary?

$regex = ObjCreate("VBScript.RegExp")
$regex.Pattern = "="
$regex.Global = True
$regex.IgnoreCase = True


$test = ObjCreate("scripting.dictionary")
$test.add("=", 2)


$sentence = "="
Local $find = $regex.execute($sentence)


for $part in $find
msgbox(0,1,$part.Value)
MsgBox(0,2,$part.Value = "=")
MsgBox(0,3,$test.exists("="))
msgbox(0,4,$test.exists($part)) ;this should be true!
next

 

Thanks for any help :)

TheAutomator.

Edited by TheAutomator
  • Solution
Posted (edited)

$part is not the thing that equals "=", $part.Value is. 

MsgBox(0, 4, $test.exists($part.Value)) ;this should be true!
Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Posted

 

$part is not the thing that equals "=", $part.Value is. 

MsgBox(0, 4, $test.exists($part.Value)) ;this should be true!

 

Ow, i see  :doh:

i thought "$part" only would work to.

i'm so confused right now because i was testing it in vbscript in the meantime and have a look at this:

Set regex = New RegExp
regex.Pattern = "="
regex.Global = True
regex.IgnoreCase = True

set test = createobject("scripting.dictionary")
test.add "=", 2

sentence = "="
set find = regex.execute(sentence)

for each part in find
    msgbox part
    msgbox test.exists(part)
next

here "part" really equals "="  :think:

why isn't this working then?

TheAutomator.

Posted

I'm not 100% sure about COM object handling in AutoIt, but I guess the problem is that AutoIt has no way to know what field or method to call from the generic COM object to get the toString value.

VBScript is quite a different language. Object oriented, for one. In this case, the RegExp.execute() method returns an object of the type MatchCollection which then your iterator "part" goes through. I guess there is auto-invocation of the .Value getter/field (don't know how that works in VBscript, never used it) when you access it as a string. I.e. it works not because part equals "=", but because the string auto-invoked string representation equals "=".

Note that this is mostly guesswork, mostly based on the example this link: http://www.regular-expressions.info/vb.html

Roses are FF0000, violets are 0000FF... All my base are belong to you.

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
×
×
  • Create New...