Need help with regex matching Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Killaz
Posts: 11
Joined: 23 Aug 2016, 16:59

Need help with regex matching

19 Feb 2017, 08:45

Hello. I have this code right here:

Code: Select all

Str := "The President: [Quiet: We do have economic problems]"
RegExMatch(Str, "^.*: \K.*", m)
MsgBox % m
What I basically need is to match all characters that come after the first ":", but for some reason Regex matches whatever comes after the second one.


Thanks. <3
Ovg
Posts: 23
Joined: 19 Feb 2017, 01:13

Re: Need help with regex matching

19 Feb 2017, 10:48

Why not use "(?<=:).*"
It's impossible to lead us astray for we don't care even to choose the way.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Need help with regex matching  Topic is solved

19 Feb 2017, 10:52

It just needed a ? to make it ungreedy:

Code: Select all

;before the first ':'
Str := "The President: [Quiet: We do have economic problems]"
RegExMatch(Str, "^.*?(?=:)", m)
MsgBox % m

;after the first ': '
Str := "The President: [Quiet: We do have economic problems]"
RegExMatch(Str, "^.*?: \K.*", m)
MsgBox % m
Return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Nerafius and 107 guests