regex question Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
joshatt
Posts: 105
Joined: 07 Dec 2014, 08:41
Facebook: joshatt
Google: joshatt

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: 4492
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: 476
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: 105
Joined: 07 Dec 2014, 08:41
Facebook: joshatt
Google: joshatt

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: 105
Joined: 07 Dec 2014, 08:41
Facebook: joshatt
Google: joshatt

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: 7114
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: 476
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”

Who is online

Users browsing this forum: Google [Bot], JoeWinograd, marqqer, NOLLIE, songdg, Xtra and 32 guests