finding a number in a string Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

finding a number in a string

Post by JustinNL » 01 Sep 2020, 13:43

Dear all,

I have been using AHK for a while and getting more into scripting.

I'm trying to get AHK to get a number from the subject line of an email.
The subject line may be "Re: information on 22897654" or "question concerning 88355667" or something like that.
To do this I have used WinGetTitle to convert the current window title in ms outlook to a string

Then I want AHK to only find the number in this string and save this as a new string. There will only be one such a number in the string
This number always consists of 8 characters, e.g. 12345678 or 22345678

By searching online, I found that RegEx may be an option, but when I look into it I can't find how to exactly use it.

Do you have any suggestions?

Thanks a lot,
best,
Justin

w0z
Posts: 230
Joined: 19 Jun 2014, 08:21

Re: finding a number in a string

Post by w0z » 01 Sep 2020, 14:29

Example:

Code: Select all

F1::
	linestring := "Re: information on 22897654"
	Getnumbers := RegExReplace(linestring, "\D")		;Get only the numbers from a string
	MsgBox, % Getnumbers
Return

If I was helpful consider Donate me. :beer: , plz :D

JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

Re: finding a number in a string

Post by JustinNL » 02 Sep 2020, 12:53

Thanks w0z, I’m sure this will work.
However is it also possible to restrict RegEx to an 8 digit number? Just in case that there are multiple numbers in the original string? (And just one 8 digit number?)

Best, Justin

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: finding a number in a string  Topic is solved

Post by Xtra » 02 Sep 2020, 13:05

Code: Select all

linestring := "Re: 123 - information on 22897654"
RegExMatch(linestring, "\d{8}", match)		;Get only the 8 digits from a string
MsgBox, % match


JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

Re: finding a number in a string

Post by JustinNL » 02 Sep 2020, 13:49

Thanks!!

Post Reply

Return to “Ask for Help (v1)”