Basic Regex question

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Basic Regex question

30 Jun 2016, 01:07

I am trying to catch the last number in the Haystack-string but I only get nothing. I have tried using this:

Code: Select all

Haystack = "Item      >  30183692"
NewStr := RegExReplace(Haystack, \s*Item\s*\>\s*(\d*)")
MsgBox, %NewStr%
What am I doing wrong?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Basic Regex question

30 Jun 2016, 01:34

Try this:

Code: Select all

Haystack := "Item      >  30183692"
NewStr := RegExReplace(Haystack, "\s*Item\s*\>\s*(\d*)", "$1")
MsgBox, %NewStr%
I hope that helps.
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Re: Basic Regex question

30 Jun 2016, 01:48

Thanks, but I can't get it to work
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Basic Regex question

30 Jun 2016, 01:50

Please, post some code that demonstrates your problem.
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Re: Basic Regex question

30 Jun 2016, 01:57

Sorry, I must have done something wrong. I tried again and now it works :).
Thanks
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Re: Basic Regex question

30 Jun 2016, 02:09

I tried reading about Replacements in the regexreplace documentation but I did not quite understand. Is it possible to specify multiple capture-groups, and how do I in that case get them into separate variables?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Basic Regex question

30 Jun 2016, 03:04

Try with RegExMatch:

Code: Select all

Haystack := "Listed things"
RegExMatch(Haystack, "(.*)\s(.*)", match)
ListVars
MsgBox
I hope that helps.
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Re: Basic Regex question

30 Jun 2016, 03:14

Ok, thanks again. But now I got a new question again :)

Code: Select all

Haystack = 
(
Sub Transfer (HSS)
 
 
Item      >30034637
Desc      :DP16/550 MAX 2008
From Sub  >MAX
Loc       ]MAX.PLOCK.02.
UOM       >TH(1 TH)
On Hand   :388
Avail Qty :388
Qty       :
To Sub    >
Reason    >
<Save/Next>
<Done>
<Cancel>
           Sub Transfer (HSS)
 
Qty       :
           Sub Transfer (HSS)
Required Field
)


NewStr := RegExReplace(Haystack, "\s*Item\s*\\>\s*(\d{8})", "$1")
MsgBox, %NewStr%
It just returns the whole String, what am I doing wrong this time?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Basic Regex question

30 Jun 2016, 03:41

When RegExReplace can't perform any replacements, it will return the Haystack unchanged. There was a typo with backslashes in there.
Try this:

Code: Select all

Haystack =
(
Sub Transfer (HSS)


Item      >30034637
Desc      :DP16/550 MAX 2008
From Sub  >MAX
Loc       ]MAX.PLOCK.02.
UOM       >TH(1 TH)
On Hand   :388
Avail Qty :388
Qty       :
To Sub    >
Reason    >
<Save/Next>
<Done>
<Cancel>
           Sub Transfer (HSS)

Qty       :
           Sub Transfer (HSS)
Required Field
)

RegExMatch(Haystack, "\s*Item\s*\>\s*(\d{8})", test)
MsgBox, % test1
I hope that helps.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mstrauss2021, peter_ahk, Spawnova, william_ahk, zephyrus2706 and 354 guests