Adding one space after each number

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

Adding one space after each number

21 Nov 2017, 19:43

bleh = 987654

I would like to create a variable from that 9 8 7 6 5 4

what would be the right way? regex? and if so, what is the regex code?

thank you
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: Adding one space after each number

21 Nov 2017, 20:57

Code: Select all

bleh = 987654

msgbox, % RegExReplace(bleh, "(\d)", "$1 ")
Baba Katchka

Re: Adding one space after each number

22 Nov 2017, 03:31

User wrote:

Code: Select all

bleh = 987654

msgbox, % RegExReplace(bleh, "(\d)", "$1 ")
works really well, what do i add so it does it regardless if its a digit or letter? I tried RegExReplace(bleh, "(\d\w)", "$1 ") but it didnt work
thanks
iPhilip
Posts: 822
Joined: 02 Oct 2013, 12:21

Re: Adding one space after each number

22 Nov 2017, 06:38

Try this:

Code: Select all

bleh = 98abc7654

msgbox, % RegExReplace(bleh, "[a-zA-Z0-9]", "$0 ")
Cheers!
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
Baba Katchka

Re: Adding one space after each number

22 Nov 2017, 07:03

iPhilip wrote:Try this:

Code: Select all

bleh = 98abc7654

msgbox, % RegExReplace(bleh, "[a-zA-Z0-9]", "$0 ")
Cheers!
I have this, is there a downside to it? "(\w)", "$1 ")
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: Adding one space after each number

22 Nov 2017, 09:03

Baba Katchka wrote:I have this, is there a downside to it? "(\w)", "$1 ")
you can use the code below too, though I think iPhilip approach is more suitable!

The code below adds one space after any character within the original text, including space character itself!

Code: Select all

bleh := "ABC D `r`n`r`n[(* % `r`n`r`n123 4"

blehSpace := RegExReplace(bleh, ".", "$0 ")

msgbox, % bleh "`n______________`n`n" blehSpace
iPhilip
Posts: 822
Joined: 02 Oct 2013, 12:21

Re: Adding one space after each number

22 Nov 2017, 11:35

Baba Katchka wrote:I have this, is there a downside to it? "(\w)", "$1 ")
That would work as well but the \w syntax matches alphanumeric or underscore, which is different than your original requirement:
Baba Katchka wrote:... it does it regardless if its a digit or letter
Also, note that subpatterns are not necessary in this solution. As shown above, the "\w", "$0 " syntax works, where $0 is the substring that matched the entire pattern.

Cheers!
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 224 guests