Regular Expressions (RegEx) To convert to ahk code Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Sheldz
Posts: 6
Joined: 21 Apr 2018, 10:55

Regular Expressions (RegEx) To convert to ahk code

22 Apr 2018, 11:01

Hi Everyone,

I need help in putting this regular expression into code. (String/Haystack below).

Code: Select all

Proforma 6 831 718 Production To Start
Customer ID 040035 Invoice to CALEFRA SERVICES
Sales person DBN - Jerome Delivery method Customer to Collect
Order number JC14217 RBay Caravan Park
Cage 0
Qty Description Colour Size List Selling Royalty Discount Total
1 Corporate Flag -
Single Sided -
Digital
Sundry 1200 x
900
490,00 490,00 0,00 0,00 490,00
1 Wind Cheater Banners Deluxe - Single N/A
Sided - Digital
3m 556,99 556,99 0,00 0,00 556,99
1 Corporate Flag - Single Sided - Digital N/A Custom 0,00 0,00 0,00 0,00 0,00
R 1,046.99
Total
Discount
Sub Total
R 0.00
R 1,046.99
VAT
Grand Total
R 146.58
R 1,193.57
(?<=number\s).*||(?<=Invoice\sto\s).*|(?<=Proforma\s).*(?=\sProduction)|(?<=person\s).*(?=\sDelivery)
I find the Customer ID, Sales Person, Proforma Number with the regex above. I would then save these contents into a variable called firstStrings for use with the end step


\d{0,5}\s(?<!R\s)\d{1,4}\,\d{1,4}.+$
I then use the above to search for the below values and would then need to delete these numbers and in then place a one comma in their place

490,00 490,00 0,00 0,00 490,00
0,00 0,00 0,00 0,00 0,00
556,99 556,99 0,00 0,00 556,99

So now the entire string looks like this:

Code: Select all

Proforma 6 831 718 Production To Start
Customer ID 040035 Invoice to CALEFRA SERVICES
Sales person DBN - Jerome Delivery method Customer to Collect
Order number JC14217 RBay Caravan Park
Cage 0
Qty Description Colour Size List Selling Royalty Discount Total
1 Corporate Flag -
Single Sided -
Digital
Sundry 1200 x
900,
1 Wind Cheater Banners Deluxe - Single N/A
Sided - Digital
3m,
1 Corporate Flag - Single Sided - Digital N/A Custom,
R 1,046.99
Total
Discount
Sub Total
R 0.00
R 1,046.99
VAT
Grand Total
R 146.58
R 1,193.57

(?<=number\s).*||(?<=Invoice\sto\s).*|(?<=Proforma\s).*(?=\sProduction)|(?<=person\s).*(?=\sDelivery)
Using this regex I get to now select the line item products only and then keep those and delete everything else in the string

Code: Select all

1 Corporate Flag -
Single Sided -
Digital
Sundry 1200 x
900,
1 Wind Cheater Banners Deluxe - Single N/A
Sided - Digital
3m,
1 Corporate Flag - Single Sided - Digital N/A Custom,
Then I search for every newline (\n) character then do a backspace with one space to get the following

Code: Select all

1 Corporate Flag - Single Sided - Digital Sundry 1200 x 900, Wind Cheater Banners Deluxe - Single N/A Sided - Digital 3m, 1 Corporate Flag - Single Sided - Digital N/A Custom,
- Search for each comma with (?<=,). and replace with a newline.
- Then find the end of the string with $ and delete those commas
- Lastly add a comma to the beginning numbers of each line ^\d{1,5}\K\s

Code: Select all

1, Corporate Flag - Single Sided - Digital Sundry 1200 x 900
1, Wind Cheater Banners Deluxe - Single N/A Sided - Digital 3m
12, Corporate Flag - Single Sided - Digital N/A Custom
And finally with this new variable of list items I find the beginning of each line with ^ and concatenate them with the firstStrings which we found in the beginning.

Code: Select all

firstStrings.1, Corporate Flag - Single Sided - Digital Sundry 1200 x 900
firstStrings.1, Wind Cheater Banners Deluxe - Single N/A Sided - Digital 3m
firstStrings.12, Corporate Flag - Single Sided - Digital N/A Custom
Long post but i hope someone can help
Last edited by Sheldz on 28 Apr 2018, 00:26, edited 1 time in total.
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Regular Expressions (RegEx) To convert to ahk code  Topic is solved

28 Apr 2018, 11:16

I hope this helps:

Code: Select all

H =
(join`r`n
Proforma 6 831 718 Production To Start
Customer ID 040035 Invoice to CALEFRA SERVICES
Sales person DBN - Jerome Delivery method Customer to Collect
Order number JC14217 RBay Caravan Park
Cage 0
Qty Description Colour Size List Selling Royalty Discount Total
1 Corporate Flag -
Single Sided -
Digital
Sundry 1200 x
900
490,00 490,00 0,00 0,00 490,00
1 Wind Cheater Banners Deluxe - Single N/A
Sided - Digital
3m 556,99 556,99 0,00 0,00 556,99
1 Corporate Flag - Single Sided - Digital N/A Custom 0,00 0,00 0,00 0,00 0,00
R 1,046.99
Total
Discount
Sub Total
R 0.00
R 1,046.99
VAT
Grand Total
R 146.58
R 1,193.57
)

while pos := RegExMatch(H, "`am)(?<=number\s).*|(?<=Invoice\sto\s).*|(?<=Proforma\s).*(?=\sProduction)|(?<=person\s).*(?=\sDelivery)", m, A_Index=1?1:pos+StrLen(m))
	firstStrings .= m " " 

H := RegExReplace(H, "s)^.*?Qty Description Colour Size List Selling Royalty Discount Total\R+")

H := RegExReplace(H, "`am)(\s?\d+,\d+)+$", "<<>>")

while pos := RegExMatch(H, "`ams)[^<>].*?(?=<<>>)", m, A_Index=1?1:pos+StrLen(m))
	res .= firstStrings . RegExReplace(m, "\R+") "`r`n"

MsgBox % res
Sheldz
Posts: 6
Joined: 21 Apr 2018, 10:55

Re: Regular Expressions (RegEx) To convert to ahk code

28 Apr 2018, 15:23

Thank you so much this gives me a general idea of what to do! I needed the commas and the regex to select those matches like i can in sublime, but this is stuff I can try play and figure out.

I appreciate you taking the time out to read that long post lol

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750, Rohwedder and 292 guests