Need to modify a string

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Need to modify a string

17 Oct 2018, 16:46

This works to make all letters in a string that are connected to digits uppercase. For example makes bb30 go to BB30 or 30bb go to 30BB.

SubstrUpperCase := RegExReplace(SubstrUpperCase, "\b([a-zA-Z]*)(\d+)([a-zA-Z]*)\b", "$U1$2$U3")

I now need to make bb-30 go to BB-30 or 30-bb go to 30-BB.
I tried Several variations of this

SubstrUpperCase := RegExReplace(SubstrUpperCase, "\b([a-zA-Z]*)(\W+)(\d+)(\W+)([a-zA-Z]*)\b", "$U1$2$U3")

But nothing is working. Thanks
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Need to modify a string

17 Oct 2018, 16:58

Code: Select all

MsgBox % RegExReplace("bb30 30bb bb-30 30-bb bb30bb bb-30-bb", "\b([a-zA-Z]*)(\W*)(\d+)(\W*)([a-zA-Z]*)\b", "$U1$2$3$4$U5")
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Re: Need to modify a string

05 Nov 2018, 07:07

Hello, It now seems the solution from swagfag was not just what I needed. If I start with this string "This 456-mh-666-g-87 Part" I need to end up with this "This 456-MH-666-G-87 Part" and I am getting this "THIS 456-MH-666-G-87 PART". I just want letters that are attached to numbers with "-" to be uppercase. I'm needing "This" and "Part" to just be left alone because they are not connected with "-". thanks
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Need to modify a string

05 Nov 2018, 07:55

This might work, using look-ahead/look-behind assertions.

Code: Select all

q::
vText := "I now need to make bb-30 go to BB-30 or 30-bb go to 30-BB."
vText := "This 456-mh-666-g-87 Part"
vText := RegExReplace(vText, "[A-Za-z]+(?=-\d)", "$U0")
vText := RegExReplace(vText, "\d-\K([A-Za-z]+)", "$U0")
MsgBox, % vText
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Re: Need to modify a string

05 Nov 2018, 08:51

Thanks jeeswg... That seems to have cleaned this up.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: GEOVAN, jollyjoe and 221 guests