best way to make many changes to a match in regex

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bazkeys
Posts: 98
Joined: 20 Jan 2021, 21:58

best way to make many changes to a match in regex

Post by bazkeys » 26 Jul 2021, 04:56

I have many changes that need to be made into one line type, of which there can be 1000s in a file. The changes include both rearranging and replacing.
I think I can possibly code this with difficulty if I break it down into several components, but was wondering if is is possible to do it in just a few lines of regexreplace type code.

As an example of fairly complicated changes to a line
I want line A to be changed to line B

Line A input example: 50/2000 Warsteiner (DE) (Consignment #104637) (Unit Cost $45.92) - Apr 14 02:04 ET 2021
Line B output example: Order number ############: Consignment #2104637, $45.92 USD Warsteiner WS1 - (50/2000) - 2021/04/14 02:04 ET

So Line B keep some of the components from Line A but they are rearranged and changed. Have to create a 10 digit order number that doesn't currently exist, add a leading digit to consignment #, and change the date format.
So, is something like that possible to do in a short snippet of code, or would I have to just break it down step by step?
Any help appreciated.
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: best way to make many changes to a match in regex

Post by mikeyww » 26 Jul 2021, 05:58

Code: Select all

order := "X1234567890A", leading := 2
lineA := "50/2000 Warsteiner (DE) (Consignment #104637) (Unit Cost $45.92) - Apr 14 02:04 ET 2021"
SendInput % "{Text}" lineB(lineA, order, leading)

lineB(lineA, order, leading) {
 Static month := {Jan: 1, Feb: 2, Mar: 3, Apr:  4, May:  5, Jun:  6
                , Jul: 7, Aug: 8, Sep: 9, Oct: 10, Nov: 11, Dec: 12}
 part  := StrSplit(lineA, [" ", "#", "(", ")"]), part.17 := month[part.17]
 Return Format("Order number {1}: {9} #{2}{11}, {16} USD {4} WS1 - ({3}) - "
             . "{23}/{19:02}/{20} {21} {22}", order, leading, part*)
}
bazkeys
Posts: 98
Joined: 20 Jan 2021, 21:58

Re: best way to make many changes to a match in regex

Post by bazkeys » 26 Jul 2021, 18:22

@mikeyww
Excellent, thanks very much for your hrlp.
Post Reply

Return to “Ask for Help (v1)”