Need help breaking up words in clipboard with Regex Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
vahju
Posts: 27
Joined: 30 Sep 2013, 16:09

Need help breaking up words in clipboard with Regex

19 Nov 2016, 21:31

First off my Regex skills are lacking (like non-existent).

For work I have to copy some text from a internal application to gather some data.
I have worked out how to copy the entire text of a site to the clipboard as text.
Problem is the data that is need was in a table and now the column name and data have been crammed together with no spaces.
Spoiler
The line numbers are irrelevant what my goal is to insert ":::" in between "Action Item ID" and "123456".
I would like to do the same thing for line with "Finished By" so the results end up being "Finished By:::John Doe".

Below is my attempt at RegexReplace

Code: Select all

Var := RegExReplace(var, ")^Action Item ID", "Action Item ID:::")
Any help would be appreciated.
User avatar
JoeWinograd
Posts: 1536
Joined: 10 Feb 2014, 20:00

Re: Need help breaking up words in clipboard with Regex

19 Nov 2016, 21:58

No real need for RegEx on this one. These two very simple StringReplace statements will do it:

Code: Select all

StringReplace,Var,Var,Action Item ID,Action Item ID:::,All
StringReplace,Var,Var,Finished By,Finished By:::,All
Regards, Joe
vahju
Posts: 27
Joined: 30 Sep 2013, 16:09

Re: Need help breaking up words in clipboard with Regex

19 Nov 2016, 22:11

I tried both and nothing gets replaced.
ErrorLevel shows 0 replaced.
Below is my script just to make sure nothing else is causing the issue.

Code: Select all

var := clipboard

; ===== Set file name
FoundPos1 := RegExMatch(var, "Action Item \d+", vFileName)
FoundPos2 := RegExMatch(var, "djtpAcceptance")

If (FoundPos2 > 0)
	vFileName := "Approved " vFilename

; ===== Clean up future column headings
StringReplace,Var,Var,Action Item ID,Action Item ID:::,All
StringReplace,Var,Var,Finished By,Finished By:::,All

; ===== Write data to file to be used later in MS Power Query
FileAppend, %var%, C:\Users\me\ActionItems\%vFileName%.txt
return
User avatar
JoeWinograd
Posts: 1536
Joined: 10 Feb 2014, 20:00

Re: Need help breaking up words in clipboard with Regex  Topic is solved

19 Nov 2016, 22:37

I didn't look at the rest of your script, but put a MsgBox % Var statement before and after my two StringReplace statements and you'll see that it works. Or test this stand-alone:

Code: Select all

Var:="line 35 Action Item ID123456`nline 36 Finished ByJohnDoe"
MsgBox % Var
StringReplace,Var,Var,Action Item ID,Action Item ID:::,All
StringReplace,Var,Var,Finished By,Finished By:::,All
MsgBox % Var
It works.

Going back to the changes I suggested in your script, while you're at it, put in a MsgBox % vFileName before the FileAppend and check the ErrorLevel value after the FileAppend.
vahju
Posts: 27
Joined: 30 Sep 2013, 16:09

Re: Need help breaking up words in clipboard with Regex

21 Nov 2016, 20:42

It works.
Must have save the changes without reloading the script.
Thanks again.
User avatar
JoeWinograd
Posts: 1536
Joined: 10 Feb 2014, 20:00

Re: Need help breaking up words in clipboard with Regex

21 Nov 2016, 22:51

You're welcome. I'm glad that works for you.

Return to “Ask For Help”

Who is online

Users browsing this forum: CarPiotr, TAC109 and 63 guests