How to use Regular expression (RegEx) to complete the account no? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

How to use Regular expression (RegEx) to complete the account no?

08 Jan 2023, 11:27

Suppose I this short account number of the customer- 1012345
Now i want to complete this account no by adding- 8899 at the starting of the above account no and 000 after "10" and before "12345"of the above account no. Namely the full account number of the customer will be- 88991000012345 (14 digit). please look at this image for understanding what i want-
q.png
q.png (16.85 KiB) Viewed 301 times

i tried these codes but with fail-

Code: Select all

MsgBox % RegExReplace("1012345", "^", "8899")
I know there could be more ways to do what i want namely using commands like substr() and other string related commands and functions. But i want do it by using Regular expression for learning purpose. Please tell me how to do that...???
Thanks a lot....
I don't normally code as I don't code normally.
User avatar
mikeyww
Posts: 27198
Joined: 09 Sep 2014, 18:38

Re: How to use Regular expression (RegEx) to complete the account no?

08 Jan 2023, 11:30

Code: Select all

#Requires AutoHotkey v1.1.33
str := "1012345"
MsgBox 64, New, % acct(str)

acct(orig) {
 Return RegExReplace(orig, "(..)(.*)", "8899$1000$2")
}
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to use Regular expression (RegEx) to complete the account no?

08 Jan 2023, 11:55

mikeyww wrote:
08 Jan 2023, 11:30

Code: Select all

#Requires AutoHotkey v1.1.33
str := "1012345"
MsgBox 64, New, % acct(str)

acct(orig) {
 Return RegExReplace(orig, "(..)(.*)", "8899$1000$2")
}
thanks a lot dear mikeyww...

sir, one more question i want to ask you regarding this-

as i have these account nos- 101234 or 10123 or 1012 or 101 now i want to convert them into 14 digit account no like this-
88991000001234
88991000000123
88991000000012
88991000000001

Could please tell me how can convert them into 14 digit account no using single line of code? Namely I may have any of the following account no-
1012345
101234
10123
1012
101

Now, i want such regex code which can be applicable in all the above five scenarios to convert them into 14 digit account no namely-
88991000012345
88991000001234
88991000000123
88991000000012
88991000000001
please tell me... thanks
I don't normally code as I don't code normally.
User avatar
mikeyww
Posts: 27198
Joined: 09 Sep 2014, 18:38

Re: How to use Regular expression (RegEx) to complete the account no?  Topic is solved

08 Jan 2023, 12:07

Code: Select all

#Requires AutoHotkey v1.1.33
str := "1012345"
str := "1012"
MsgBox 64, New, % acct(str)

acct(orig) {
 ; RegExMatch(orig, "(..)(.*)", m)
 ; Return Format("8899{}{:08}", m1, m2)
 Return Format("8899{}{:08}", SubStr(orig, 1, 2), SubStr(orig, 3))
}
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to use Regular expression (RegEx) to complete the account no?

08 Jan 2023, 12:16

mikeyww wrote:
08 Jan 2023, 12:07

Code: Select all

#Requires AutoHotkey v1.1.33
str := "1012345"
str := "1012"
MsgBox 64, New, % acct(str)

acct(orig) {
 ; RegExMatch(orig, "(..)(.*)", m)
 ; Return Format("8899{}{:08}", m1, m2)
 Return Format("8899{}{:08}", SubStr(orig, 1, 2), SubStr(orig, 3))
}

thanks a lot sir....it really solved the problem..... :thumbup: :bravo:
I don't normally code as I don't code normally.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 167 guests