regex question Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

regex question

18 Feb 2019, 21:08

Code: Select all

variable = abcd-567  ; or 12abcd-567
if RegExMatch(variable,"((\d|\w)+)-(\d+)",vars)
{
	msgbox,% vars1 . "_" . vars2
}
The above code can not match as I expected. Any idea?
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: regex question

18 Feb 2019, 21:16

I am no Regex expert, but I think it would be nice if you would at least mention, what you expect as a result...
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: regex question  Topic is solved

18 Feb 2019, 21:41

I am guessing this is what you're looking for

Code: Select all

variable = abcd-567  			; or 12abcd-567
if RegExMatch(variable,"((?:\d|\w)+)-(\d+)",vars)
	msgbox,% vars1 . "_" . vars2
; or
if RegExMatch(variable,"((\d|\w)+)-(\d+)",vars)
	msgbox,% vars1 . "_" . vars3
	
; or
variable = 12abcd-567
if RegExMatch(variable,"(\w+)-(\d+)",vars)		; \w = alpha-numeric
	msgbox,% vars1 . "_" . vars2
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

Re: regex question

18 Feb 2019, 23:24

gregster wrote:
18 Feb 2019, 21:16
I am no Regex expert, but I think it would be nice if you would at least mention, what you expect as a result...
Sorry my bad, did not make it clear. I want to match the 2 or 3 possabilites (former part could be interger or word or mix) in one code.
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

Re: regex question

19 Feb 2019, 01:02

AlphaBravo wrote:
18 Feb 2019, 21:41
I am guessing this is what you're looking for

Code: Select all

variable = abcd-567  			; or 12abcd-567
if RegExMatch(variable,"((?:\d|\w)+)-(\d+)",vars)
	msgbox,% vars1 . "_" . vars2
; or
if RegExMatch(variable,"((\d|\w)+)-(\d+)",vars)
	msgbox,% vars1 . "_" . vars3
	
; or
variable = 12abcd-567
if RegExMatch(variable,"(\w+)-(\d+)",vars)		; \w = alpha-numeric
	msgbox,% vars1 . "_" . vars2
Thank you very much, I'll try to learn from this.
just me
Posts: 9450
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: regex question

19 Feb 2019, 03:49

AlphaBravo wrote:
18 Feb 2019, 21:41

Code: Select all

...
... ; \w = alpha-numeric
...
Not quite.
RegEx - Quick Reference wrote:\w ... This is equivalent to [a-zA-Z0-9_]. ...
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: regex question

19 Feb 2019, 21:00

just me wrote:
19 Feb 2019, 03:49
Not quite.
RegEx - Quick Reference wrote:\w ... This is equivalent to [a-zA-Z0-9_]. ...
fair enough ;)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RussF and 377 guests