Sign in to follow this  
Followers 0
UnKnOwned

RegEx Help

6 posts in this topic

Simply put, how do you search a string for Autoit macros using RegEx?

Here is where I am at so far.

$ret = StringRegExp($sData, '([@]{1,3})(?:\B)')

I am reading here

http://www.autoitscript.com/autoit3/docs/tutorials/regexp/regexp.htm

&

http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial

I do not use if ever regular expressions as I have been misguided but will start using them now.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Try expanding the variables - might help.

$String = "Hello"
$String_ = "$String$, nice meeting you at @scriptdir@"

MsgBox(64, "Variables not Expanded", $String_)

;check the help file for how Autoit treats macros and variables upon expanding.
Opt("ExpandVarStrings", 1)

MsgBox(64, "Variables Expanded", $String_) 

You have to hard-code all the macros if you want only Autoit - explicit macros. Otherwise any word("w") followed by a "@" would do.

Regards ;)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

@PhoenixXL

I'm not quite sure I follow in terms of expanding Autoit @macros to their values, and since I seem to be terrible at asking questions, I will just show you what I am trying to accomplish.

Read ini file sections set key names to Autoit usable variables set key values to Autoit variable values derived from ini key names. At the moment I am only interested in replacing the macros for their values.

Snippet

Local $Config_File = '.config.ini'
Local $INI_Sections = IniReadSectionNames($Config_File)

For $i = 1 to $INI_Sections[0]
    $S_Name = IniReadSection($Config_File, $INI_Sections[$i])
    For $x = 1 To $S_Name[0][0]
        Assign($S_Name[$x][0], get($S_Name[$x][1], 'INI|val'))
    Next
Next

Func get($sData, $stype)
    Switch $stype
        Case 'INI|val'
            $ret = _LitMacs($sData)
            Return($ret)
            
    EndSwitch
EndFunc

To make this work I use this mess

Func _LitMacs($sData)
    $ret = StringReplace($sData, '@AppDataCommonDir', @AppDataCommonDir)
    $ret = StringReplace($ret, '@AppDataDir', @AppDataDir)
    $ret = StringReplace($ret, '@AutoItExe', @AutoItExe)
    $ret = StringReplace($ret, '@AutoItPID', @AutoItPID)
    $ret = StringReplace($ret, '@AutoItVersion', @AutoItVersion)
    $ret = StringReplace($ret, '@AutoItX64', @AutoItX64)
    ;$ret = StringReplace($ret, '@COM_EventObj', @COM_EventObj)
    $ret = StringReplace($ret, '@CommonFilesDir', @CommonFilesDir)
    $ret = StringReplace($ret, '@Compiled', @Compiled)
    $ret = StringReplace($ret, '@ComputerName', @ComputerName)
    $ret = StringReplace($ret, '@ComSpec', @ComSpec)
    $ret = StringReplace($ret, '@CPUArch', @CPUArch)
    $ret = StringReplace($ret, '@CR', @CR)
    $ret = StringReplace($ret, '@CRLF', @CRLF)
    $ret = StringReplace($ret, '@DesktopCommonDir', @DesktopCommonDir)
    $ret = StringReplace($ret, '@DesktopDir', @DesktopDir)
    $ret = StringReplace($ret, '@DesktopHeight', @DesktopHeight)
    $ret = StringReplace($ret, '@DesktopWidth', @DesktopWidth)
    $ret = StringReplace($ret, '@DesktopDepth', @DesktopDepth)
    $ret = StringReplace($ret, '@DesktopRefresh', @DesktopRefresh)
    $ret = StringReplace($ret, '@DocumentsCommonDir', @DocumentsCommonDir)
    $ret = StringReplace($ret, '@error', @error)
    ;$ret = StringReplace($ret, '@exitCode', @exitCode)
    ;$ret = StringReplace($ret, '@exitMethod', @exitMethod)
    $ret = StringReplace($ret, '@extended', @extended)
    $ret = StringReplace($ret, '@FavoritesCommonDir', @FavoritesCommonDir)
    $ret = StringReplace($ret, '@FavoritesDir', @FavoritesDir)
    ;$ret = StringReplace($ret, '@GUI_CtrlId', @GUI_CtrlId)
    ;$ret = StringReplace($ret, '@GUI_CtrlHandle', @GUI_CtrlHandle)
    ;$ret = StringReplace($ret, '@GUI_DragId', @GUI_DragId)
    ;$ret = StringReplace($ret, '@GUI_DragFile', @GUI_DragFile)
    ;$ret = StringReplace($ret, '@GUI_DropId', @GUI_DropId)
    ;$ret = StringReplace($ret, '@GUI_WinHandle', @GUI_WinHandle)
    $ret = StringReplace($ret, '@HomeDrive', @HomeDrive)
    $ret = StringReplace($ret, '@HomePath', @HomePath)
    $ret = StringReplace($ret, '@HomeShare', @HomeShare)
    $ret = StringReplace($ret, '@HOUR', @HOUR)
    $ret = StringReplace($ret, '@HotKeyPressed', @HotKeyPressed)
    $ret = StringReplace($ret, '@IPAddress1', @IPAddress1)
    $ret = StringReplace($ret, '@IPAddress2', @IPAddress2)
    $ret = StringReplace($ret, '@IPAddress3', @IPAddress3)
    $ret = StringReplace($ret, '@IPAddress4', @IPAddress4)
    $ret = StringReplace($ret, '@KBLayout', @KBLayout)
    $ret = StringReplace($ret, '@LF', @LF)
    $ret = StringReplace($ret, '@LogonDNSDomain', @LogonDNSDomain)
    $ret = StringReplace($ret, '@LogonDomain', @LogonDomain)
    $ret = StringReplace($ret, '@LogonServer', @LogonServer)
    $ret = StringReplace($ret, '@MDAY', @MDAY)
    $ret = StringReplace($ret, '@MIN', @MIN)
    $ret = StringReplace($ret, '@MON', @MON)
    $ret = StringReplace($ret, '@MSEC', @MSEC)
    $ret = StringReplace($ret, '@MUILang', @MUILang)
    $ret = StringReplace($ret, '@MyDocumentsDir', @MyDocumentsDir)
    $ret = StringReplace($ret, '@NumParams', @NumParams)
    $ret = StringReplace($ret, '@OSArch', @OSArch)
    $ret = StringReplace($ret, '@OSBuild', @OSBuild)
    $ret = StringReplace($ret, '@OSLang', @OSLang)
    $ret = StringReplace($ret, '@OSServicePack', @OSServicePack)
    $ret = StringReplace($ret, '@OSType', @OSType)
    $ret = StringReplace($ret, '@OSVersion', @OSVersion)
    $ret = StringReplace($ret, '@ProgramFilesDir', @ProgramFilesDir)
    $ret = StringReplace($ret, '@ProgramsCommonDir', @ProgramsCommonDir)
    $ret = StringReplace($ret, '@ProgramsDir', @ProgramsDir)
    $ret = StringReplace($ret, '@ScriptDir', @ScriptDir)
    $ret = StringReplace($ret, '@ScriptFullPath', @ScriptFullPath)
    $ret = StringReplace($ret, '@ScriptLineNumber', @ScriptLineNumber)
    $ret = StringReplace($ret, '@ScriptName', @ScriptName)
    $ret = StringReplace($ret, '@SEC', @SEC)
    $ret = StringReplace($ret, '@StartMenuCommonDir', @StartMenuCommonDir)
    $ret = StringReplace($ret, '@StartMenuDir', @StartMenuDir)
    $ret = StringReplace($ret, '@StartupCommonDir', @StartupCommonDir)
    $ret = StringReplace($ret, '@StartupDir', @StartupDir)
    $ret = StringReplace($ret, '@SW_DISABLE', @SW_DISABLE)
    $ret = StringReplace($ret, '@SW_ENABLE', @SW_ENABLE)
    $ret = StringReplace($ret, '@SW_HIDE', @SW_HIDE)
    $ret = StringReplace($ret, '@SW_LOCK', @SW_LOCK)
    $ret = StringReplace($ret, '@SW_MAXIMIZE', @SW_MAXIMIZE)
    $ret = StringReplace($ret, '@SW_MINIMIZE', @SW_MINIMIZE)
    $ret = StringReplace($ret, '@SW_RESTORE', @SW_RESTORE)
    $ret = StringReplace($ret, '@SW_SHOW', @SW_SHOW)
    $ret = StringReplace($ret, '@SW_SHOWDEFAULT', @SW_SHOWDEFAULT)
    $ret = StringReplace($ret, '@SW_SHOWMAXIMIZED', @SW_SHOWMAXIMIZED)
    $ret = StringReplace($ret, '@SW_SHOWMINIMIZED', @SW_SHOWMINIMIZED)
    $ret = StringReplace($ret, '@SW_SHOWMINNOACTIVE', @SW_SHOWMINNOACTIVE)
    $ret = StringReplace($ret, '@SW_SHOWNA', @SW_SHOWNA)
    $ret = StringReplace($ret, '@SW_SHOWNOACTIVATE', @SW_SHOWNOACTIVATE)
    $ret = StringReplace($ret, '@SW_SHOWNORMAL', @SW_SHOWNORMAL)
    $ret = StringReplace($ret, '@SW_UNLOCK', @SW_UNLOCK)
    $ret = StringReplace($ret, '@SystemDir', @SystemDir)
    $ret = StringReplace($ret, '@TAB', @TAB)
    $ret = StringReplace($ret, '@TempDir', @TempDir)
    ;$ret = StringReplace($ret, '@TRAY_ID', @TRAY_ID)
    $ret = StringReplace($ret, '@TrayIconFlashing', @TrayIconFlashing)
    $ret = StringReplace($ret, '@TrayIconVisible', @TrayIconVisible)
    $ret = StringReplace($ret, '@UserProfileDir', @UserProfileDir)
    $ret = StringReplace($ret, '@UserName', @UserName)
    $ret = StringReplace($ret, '@WDAY', @WDAY)
    $ret = StringReplace($ret, '@WindowsDir', @WindowsDir)
    $ret = StringReplace($ret, '@WorkingDir', @WorkingDir)
    $ret = StringReplace($ret, '@YDAY', @YDAY)
    $ret = StringReplace($ret, '@YEAR', @YEAR)
    Return($ret)
EndFunc

Thank you in advance.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Here is the simplest solution

$String_ = Execute("@scriptdir")
MsgBox(64, "Variable", $String_)

Your script

Local $Config_File = '.config.ini'
Local $INI_Sections = IniReadSectionNames($Config_File)

For $i = 1 To $INI_Sections[0]
    $S_Name = IniReadSection($Config_File, $INI_Sections[$i])
    For $x = 1 To $S_Name[0][0]
        Assign($S_Name[$x][0], get($S_Name[$x][1]))
    Next
Next

Func get($sData)
    Return Execute($sData)
EndFunc   ;==>get

P.S. I don't know how your INI file is containing the data. The script would work only if $S_Name[$x][1] is only a Macro

Otherwise please post the format of how the data is stored in your INI.

Regards ;)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@PhoenixXL

ini contains strings where the macro is not the first or only param, and could be surrounded by other strings hence the question about re.

[section]
key=Time today is @hour:@min:@sec

P.S. Good stuff here, personal thanks for keeping notes like this.

@YogiBear

I also wanted to add some thanks for the direction as well. After some research of the regex tool included in the help file I was led here 

Regular expressions do not seem so bad it is like learning dos for %x () //%*#&@^^ crap all over again except with a much more powerful result.

Edited by UnKnOwned

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
Sign in to follow this  
Followers 0