RegExReplace & Uppercase Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bilows

RegExReplace & Uppercase

27 Jun 2017, 21:53

Authohotkey doesn't have an option in StringUpper to capitalize letters after an hyphen (HINT: request).

This rock-hard cake => This Rock-hard Cake
vs
This rock-hard cake => This Rock-Hard Cake

How do I uppercase all letters after an hyphen: [a-z]-[a-z] => [a-z]-[A-Z]

RegExReplace(aString, "[a-z]\-([a-z])", "$U1")
or
RegExReplace(aString, "\-([a-z])", "$U1")
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: RegExReplace & Uppercase

28 Jun 2017, 01:50

Code: Select all

MsgBox % RegExReplace( "brown-fox jumps-over", "([a-z]\-)([a-z])", "$1$U2")
Guest

Re: RegExReplace & Uppercase

28 Jun 2017, 07:00

The example works, but this doesn't:

Code: Select all

RegExReplace(aString, "([a-z]\-)([a-z])", "$1$U2")
keyes
Posts: 33
Joined: 27 Jun 2017, 21:42

Re: RegExReplace & Uppercase

28 Jun 2017, 07:11

Example with string works, but this doesn't:

Code: Select all

RegExReplace(aString, "([a-z]\-)([a-z])", "$1$U2")
But adding "MsgBox %" before code above works.

Since I'm using the RegExReplace inside a function, how to I make the changes to the variable so I can send it back as the result?

Code: Select all

RegExReplace(aString,"([a-z]\-)([a-z])","$1$U2")
Return aString
Last edited by keyes on 28 Jun 2017, 07:16, edited 1 time in total.
Guest

Re: RegExReplace & Uppercase  Topic is solved

28 Jun 2017, 07:15

of course it works, you just need to assign it back to a variable (can be the same) just call RegExReplace() on its own doesn't change the contents of the string

Code: Select all

aString:="brown-fox jumps-over"
aString:=RegExReplace(aString, "([a-z]\-)([a-z])", "$1$U2")
MsgBox % aString
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: RegExReplace & Uppercase

28 Jun 2017, 07:22

Code: Select all

Return RegExReplace(aString,"([a-z]\-)([a-z])","$1$U2")
keyes
Posts: 33
Joined: 27 Jun 2017, 21:42

Re: RegExReplace & Uppercase

28 Jun 2017, 07:37

aString = variable that contains selected text (example: "the brown-fox in house")

1) StringUpper(aString) => "The Brown-fox In House"

2) myPrepositionsFix(aString) => "The Brown-fox in House"

Code: Select all

aString = % RegExReplace(aString,"(\-)([a-z])","$1$U2")
aString => "The Brown-Fox in House"

Needed to assign result of RegExReplace this way: aString = % RegExReplace()
Last edited by keyes on 28 Jun 2017, 07:51, edited 4 times in total.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: RegExReplace & Uppercase

28 Jun 2017, 07:40

RegEx is not the point here.
Read the Help file.
Expression section.

That is really dirty part of AHK.
Should be fixed.
keyes
Posts: 33
Joined: 27 Jun 2017, 21:42

Re: RegExReplace & Uppercase

28 Jun 2017, 07:43

Never used RegEx in Autohotkey before so missed the assignment detail.

I see your point.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Theda and 274 guests