Need A Quick Regex To Extract Numbers

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Roonyroo
Posts: 36
Joined: 29 Jan 2014, 20:29

Need A Quick Regex To Extract Numbers

20 Mar 2014, 14:53

I still havent figured out how to use regex yet, need to set aside a weekend to get the hang of it ...

In the meanwhile I need to extract all numbers before the 1st "="

ie winxlxc93=ypos:=Foundy%xs% the number extracted should be 93

Thanks in advance
Guest

Re: Need A Quick Regex To Extract Numbers

20 Mar 2014, 15:13

[code]var:="winxlxc93=ypos:=Foundy%xs%"
RegExMatch(var,"(\d+)=",number)
MsgBox % Number "`n" Number1 ; note the difference between number and number1[/code]
Roonyroo
Posts: 36
Joined: 29 Jan 2014, 20:29

Re: Need A Quick Regex To Extract Numbers

20 Mar 2014, 16:59

Thats great

Why does number show = & number1 doesnt? Is Number1 the matched number?
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Need A Quick Regex To Extract Numbers

20 Mar 2014, 18:09

The parenthesis in the regular expression are used to capture a sub-pattern. Here is a simple example:

Code: Select all

TestText := "92837465"
RegExMatch(TestText, "(\d)(\d)(\d)(\d+)", m)
MsgBox, % "m:`t" m "`nm1:`t" m1 "`nm2:`t" m2 "`nm3:`t" m3 "`nm4:`t" m4
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 366 guests