Pulling words from text file

Get help with using AutoHotkey and its commands and hotkeys
Twinbrow
Posts: 6
Joined: 14 Jan 2017, 13:41

Pulling words from text file

19 Jan 2021, 22:41

I am not having good luck with this process. I am trying to send a text file to clipboard then parsing it to pull out every word after $ and display it.

hi $my name $is Chad, how are $you today


list

my
is
you

I found this and tried different things but its a bit beyond me.

Code: Select all

TestText := clipboard
p := RegExMatch(TestText, "$ \K\w+", m)
MsgBox, % m
User avatar
Chunjee
Posts: 784
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: Pulling words from text file

19 Jan 2021, 23:40

But you can't msgbox the results like that.

https://www.autohotkey.com/docs/commands/RegExMatch.htm :
If any capturing subpatterns are present inside NeedleRegEx, their matches are stored in a pseudo-array
User avatar
Chunjee
Posts: 784
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: Pulling words from text file

19 Jan 2021, 23:51

Changed the regex a lot:

Code: Select all

clipboard := "hi $my name $is Chad, how are $you today"
RegExMatch(clipboard, "\$(\w+).*\$(\w+).*\$(\w+)", m)
if (m1) {
	msgbox, % m1
	; => my
}
if (m2) {
	msgbox, % m2
	; => is
}
if (m3) {
	msgbox, % m3
	; => you
}
https://regex101.com/r/SkfJs6/1
User avatar
boiler
Posts: 6838
Joined: 21 Dec 2014, 02:44

Re: Pulling words from text file

20 Jan 2021, 05:37

Without having to know in advance how many results there are and without limiting the number of possible results:

Code: Select all

TestText := "hi $my name $is Chad, how are $you today"
s := 1
while f := RegExMatch(TestText, "(?<=\$)\w+", m, s)
	TextOut .= m "`n", s:= f + StrLen(m)
MsgBox, % TextOut
Could assign the found words to an array if desired.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], hasantr, Xeo786 and 44 guests