regexreplace performance issue? maybe?
I am exporting old Lotus Notes documents from a database. During which I need to convert the titles of the documents with a strings like
Regex: Test./*,.|?"
Into
Regex_ Test_________
so Windows doesn't puke on the file name when I export it. I know my regex works, but...
Here is the newbie script I wrote this morning:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
^#e:: ; hotkey to start
Loop, 402
{
Sleep 1000
Send {Enter} ; Enter to open/select next
Sleep 1000
MouseClickDrag, left, 473, 217, 807, 217 ; drag subject
Sleep 500
Send ^c ; copy with ctrl+c
ClipWait
string := Clipboard
Clipboard := RegExReplace(string, "i)[^0-9a-z]","_")
;MsgBox % ErrorLevel
Sleep 500
Send !f
Sleep 500
Send e
Sleep 500
Send {Enter}
Sleep 500
Send !t ; alt+t
Sleep 500
Send {Down 3}
Sleep 500
Send {Enter}
Sleep 500
Send !n ; alt+n
Sleep 500
Send ^v ; ctrl+v
Sleep 500
Send {NumpadDot}rtf
Sleep 500
Send !x ; alt+x
}
return
The problem is that when I comment out
MsgBox % ErrorLevel
or click the message box real fast, the regexreplace fails to modify my clipboard so I paste the original string later in the script. My last test is to add in a Sleep 5000 like after
Clipboard := RegExReplace(string, "i)[^0-9a-z]","_")
Sleep 5000
and this only works half the time...
I am reading that regexreplace isn't super performative, but what can I do to make my script wait "long enough" or "until the replace is done"?
Posted Sep 1, 2020, 5:25 PM UTC · edited
I may have worked around this with
Then later, instead of
I do a
Still testing and trying to tighten it up...
You can also skip the string sub step
The problem I'm having is with regex not working properly on Clipboard. It works fine on %string% to store it in %fileName%, but when I regex the clipboard itself, I get unreliable or very slow results.
I'm starting to wonder if something in my AV or something in Windows10 is trying to prevent clipboard manipulation.