Jump to content

Strangeness when reading value and running regex


Recommended Posts

I figured I'd have a go at creating a live regex tester, not a big deal right?

Input box for regex, textfield with text to test against, and an output box showing results.

But here's where it gets weird.

If I run: $resultHolder = StringRegExp( "Edit 1", "Edit", 0)

I get 1, there's a match.

But if I do: $resultHolder = StringRegExp( "Edit 1", $tempText, 0)

Where tempText is Edit, I get 0, no matches..

I can't figure it out.

Anyone run into something similar?

My *guess* is that there are extra characters ending up in the variable somehow, which throws off the regex match-

Link to comment
Share on other sites

  • Moderators

No reproducer script?

Without one, you force us to write one, then guess how you are doing things.

This would be as much work as I'd be willing to put into debugging for you with what you've provided, but it works:

Global $gs_testVar = "Edit"
Global $gb_retVal = StringRegExp("Edit 1", $gs_testVar)
ConsoleWrite($gb_retVal & @CRLF)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Allright, let's see if this works..

-edit- reading this over, I found my misteak, I flipped the StringRegExp...

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 260, 180)
$regIn = GUICtrlCreateInput("Input1", 10, 30, 591, 21)
$textToCheck = GUICtrlCreateEdit("", 10, 80, 265, 349)
GUICtrlSetData(-1, "Edit1")
$matches = GUICtrlCreateEdit("", 290, 80, 315, 169)
GUICtrlSetData(-1, "Edit2")
$Label1 = GUICtrlCreateLabel("Regex", 20, 10, 35, 17)
$Label2 = GUICtrlCreateLabel("Text", 20, 60, 25, 17)
$Label3 = GUICtrlCreateLabel("Matches", 300, 60, 45, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $tempText = ''
Global $resultHolder = ''
Global $regToRun = ''

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit

   EndSwitch

   $regToRun = GUICtrlRead($regIn)
   $tempText = GUICtrlRead($textToCheck)

   $resultHolder = StringRegExp( "Edit 1", $tempText, 0)
   GUICtrlSetData( $matches, $resultHolder & ' - ' & _NowTime())

   Sleep(100)
WEnd
Edited by MarcusFernstrom
Link to comment
Share on other sites

@ MarcusFernstrom: have you looked at the Regex script in the help file? Look for "Tutorial - Regular Expression" and at the bottom of the page there is a button (open StringRegExpGUI.au3) to open the Regex script in SciTE.

Edited by Bert
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...