Jump to content
TheAutomator

regular expression is not found in dictionary?

Recommended Posts

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

Share this post


Link to post
Share on other sites

 

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

Share this post


Link to post
Share on other sites

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.

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

  • Similar Content

    • By junichironakashima
      Im creating a code that will work in this sequence:
      1. Copy the text (question) in one atea of the screen
      2. Catch the 2 strings (number)
      3. Multiply the 2 strings ( $1*$2)
      4. Click the next area to put the answer
      5. Paste the answer
       
      This is my code
       
      MouseClick($MOUSE_CLICK_LEFT, 479, 802, 3, 1) ;Clicking all of the text
      Send("^c") 
      $x = StringRegExpReplace(ClipGet(), 'What is (\d*) x (\d*) \?$', "$1*$2")
      MouseClick($MOUSE_CLICK_LEFT, 480, 844, 1, 1)
      ClipPut($x)
      Send("^v")
       
      However the output is this
      $1*$2
       
      How can I make it solve itself? Because I tried this code:
      MouseClick($MOUSE_CLICK_LEFT, 479, 802, 3, 1) ;Clicking all of the text
      Send("^c")
      MouseClick($MOUSE_CLICK_LEFT, 480, 844, 1, 1) $x = Execute(StringRegExpReplace(ClipGet(), 'What is (\d*) x (\d*) \?$', "$1*$2"))
      ClipPut($x)
      Send("^v")
      Output is just blank text

    • By gruntydatsun
      I have an XML file and every time there are three lines in a row with only <null/> in them, i want to insert a fourth line with <null/>.   Each line starts with 3 white spaces, followed by <null/> and ends with a white space followed by CR LF.   The presence of the three lines as described is unique to the points where I want to insert a line in this document.
       I'm trying to figure out how to apply the repeating part of a regex  {1,4} but apply it to this whole segment. 
      So far I have the below which picks up an individual line ok:
      ^\s{3}<null/>\s\r\n I tried wrapping it all in braces () then adding {3} but I'm obviously getting something wrong. 
      Attached is a section from the xml file with a block of nulls that should be matched if anyone would like to have a look.
      Help_From_Forum.xml
    • By milkmoron
      I am trying to search in a web browser dates XX/XX/XXXX that are also links. I want to click them after and remove them from the array. This is all I have so far. Nothing shows up. What am I doing wrong?
      ControlFocus ("Customer Center", "", "")
      Local $aArray = StringRegExp('(..)/(..)/(....)', '(..)/(..)/(....)', $STR_REGEXPARRAYFULLMATCH)
      For $i = 0 To UBound($aArray) - 1
          MsgBox($MB_SYSTEMMODAL, "RegExp Test with Option 2 - " & $i, $aArray[$i])
      Next
       
    • By WoodGrain
      Hi All,
      I'd like to replace 'COMMA' with ',' for example:
      $myString = "COMMA" StringRegExpReplace($myString, 'COMMA', ',') Now I've tried escaping the ',' in various ways unsuccessfully, such as:
      '[,]'
      "[,]"
      '\,'
      [,] seems to work in the pattern, I just can't figure out how to use it in the replace, and it seems everyone online is only interested in removing/replacing commas lol.
      I also tried creating and using a variable as the replacement but also didn't work:
      $myComma = "," $myString = "COMMA" StringRegExpReplace($myString, 'COMMA', $myComma) I'm sure it's super simple if someone could point me in the right direction - thanks.
    • By rcmaehl
      Hi all,
      I still suck at regex as always and I need some help. According to the regex tester I normally use this should be working fine but it doesn't....
      StringRegExp($sString, "\A[1-9]+[0-9]*(\-[1-9]+[0-9]*)?,*\Z") I basically want to match:
      all numbers EXCEPT 0, but including 10, 20, etc with each number separated by a comma and allowing a "-" separated range as a value For example:
      1-5,7,10-12 I've spent a couple hours modifying it but I'm not sure where I've gone wrong. Any help would be appreciated!
×
×
  • Create New...