Page 1 of 1

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

Posted: 08 Jan 2023, 11:27
by Sabestian Caine
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 335 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....

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

Posted: 08 Jan 2023, 11:30
by mikeyww

Code: Select all

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

acct(orig) {
 Return RegExReplace(orig, "(..)(.*)", "8899$1000$2")
}

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

Posted: 08 Jan 2023, 11:55
by Sabestian Caine
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

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

Posted: 08 Jan 2023, 12:07
by mikeyww

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))
}

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

Posted: 08 Jan 2023, 12:16
by Sabestian Caine
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: