Regular expressions to convert case of text

Get help with using AutoHotkey and its commands and hotkeys
Wigi
Posts: 48
Joined: 05 Jun 2017, 10:52
Contact:

Regular expressions to convert case of text

18 Nov 2017, 16:44

Hello all,

How would I create a function to convert part of a string to uppercase or lowercase ?

An example is as follows:

blah blah blah §DimIx§( sDimension, sElement, §DimNm§( sDimension, sElement ) );

- All parts WITHIN the § characters should be uppercase or lowercase.
- The § characters mark functions (each pair of § is a function)
- The § characters need to be removed to
- The § can be changed if needed, it's just a character that is unique

End result:

blah blah blah dimix( sDimension, sElement, dimnm( sDimension, sElement ) );
or:
blah blah blah DIMIX( sDimension, sElement, DIMNM( sDimension, sElement ) );

So I started:

Code: [Select all] [Download] GeSHi © Codebox Plus

Change_Case( String, Case_type )
{

}


Case_type = U for Upper or L for Lower

I am not good at regular expressions so can someone help me please ?

Thanks a lot !
teadrinker
Posts: 307
Joined: 29 Mar 2015, 09:41

Re: Regular expressions to convert case of text

18 Nov 2017, 18:08

Hello,

Code: [Select all] [Download] GeSHi © Codebox Plus

str := "blah blah blah §DimIx§( sDimension, sElement, §DimNm§( sDimension, sElement ) );"
MsgBox, % RegExReplace(str, "§.*?§", "$L0")
MsgBox, % RegExReplace(str, "§.*?§", "$U0")
Wigi
Posts: 48
Joined: 05 Jun 2017, 10:52
Contact:

Re: Regular expressions to convert case of text

18 Nov 2017, 18:13

Hero !

I figured that § is not so good, so I changed to @

Then this works like a dream:

Code: [Select all] [Download] GeSHi © Codebox Plus

str := "blah blah blah @DimIx@( sDimension, sElement, @DimNm@( sDimension, sElement ) );"

v = % RegExReplace(str, "@.*?@", "$L0")
StringReplace, v, v, @, , all
msgbox %v%

v = % RegExReplace(str, "@.*?@", "$U0")
StringReplace, v, v, @, , all
msgbox %v%


Many thanks.
teadrinker
Posts: 307
Joined: 29 Mar 2015, 09:41

Re: Regular expressions to convert case of text

18 Nov 2017, 18:38

You could using ":=" instead of "= %":

Code: [Select all] [Download] GeSHi © Codebox Plus

v := RegExReplace(str, "@.*?@", "$L0")
This is more correct.

Return to “Ask For Help”

Who is online

Users browsing this forum: DarkKitten, honyakusha, Odlanir and 11 guests