Help with selecting a word next to another word

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
BushMange
Posts: 13
Joined: 22 Jan 2020, 04:05

Help with selecting a word next to another word

22 Jan 2020, 05:43

Dear scripting gods :D

I'm new to the forum but not AHK since i've used it to streamline many steps at my workplace.

But now i'm at a stand still, i'm trying to do a script that fetches a license plate number from our Customer service software. The Customer fills in a form and adds his or hers licenseplate number in a specific field. So the text could be anywhere between 1 to 1000 lines.

Example:

Fråga:
Hi!

This is a test!

Best regards

Registreringnummer: ABC123
Kontaktas via: epost

Namn: John Doe

So what i'm trying to do is to fetch the word next after "Registreringsnummer:", the placement changes depending on the length of the e-mail but the word stays the same. My own tries with Instr, StringGetPos, SubStr and RegExMatch has fallen short with either no data or the whole e-mail.

The software is proprietary so to get the whole text i've done like this to get the whole e-mail copied.

Code: Select all

::reg::
Clipboard =
send ^{end}^+{home} ;Select all
Send ^c
Clipwait, 1
data := Clipboard ;Clipboard contents becomes var
FoundPos := InStr(data, Registreringsnummer) ;search text for "Registreringsnummer"
Regnr := Substr(FoundPos, , 7)  ;get the text with license plate number, which could be up to 7 characters
Clipboard = %Regnr% ;add license plate number to clipboard
Any tips how you would do it, i'm thankfull for!
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Help with selecting a word next to another word

22 Jan 2020, 07:48

Code: Select all

; Clipboard =
data =
(
Fråga:
Hi!

This is a test!

Best regards

Registreringnummer: ABC123
Kontaktas via: epost

Namn: John Doe
)

; Loop, Parse, Clipboard, `n, `r
Loop, Parse, data, `n, `r
If InStr(A_LoopField, "Registreringnummer:")
	Registreringnummer := StrSplit(A_LoopField,"Registreringnummer: ").2
MsgBox, Registreringnummer = "%Registreringnummer%"
User avatar
boiler
Posts: 17086
Joined: 21 Dec 2014, 02:44

Re: Help with selecting a word next to another word

22 Jan 2020, 08:44

Using RegExMatch:

Code: Select all

Text =
(
Fråga:
Hi!

This is a test!

Best regards

Registreringnummer: ABC123
Kontaktas via: epost

Namn: John Doe
)

RegExMatch(Text, "Registreringnummer:\s*\K\w+", Registreringnummer)
MsgBox, % Registreringnummer
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Help with selecting a word next to another word

22 Jan 2020, 08:59

I like StrSplit() so much.. :D

Code: Select all

data =
(
Fråga:
Hi!

This is a test!

Best regards

Registreringnummer: ABC123
Kontaktas via: epost

Namn: John Doe
)
Registreringnummer := StrSplit(StrSplit(data,"Registreringnummer: ").2,"`n"," `t`r").1
MsgBox, Registreringnummer = "%Registreringnummer%"
BushMange
Posts: 13
Joined: 22 Jan 2020, 04:05

Re: Help with selecting a word next to another word

22 Jan 2020, 13:45

Wow! :shock:

Thanks a lot guys!

I’ve tried my own versions on all but obviously I used the wrong options on RegEx, built parse loop wrong and made a mess of StrSplit.

Thanks again! You made my day!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww and 158 guests