need help on Regexmatch to store multiple variables

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

need help on Regexmatch to store multiple variables

05 Aug 2021, 19:19

Hi Hi,

I need help to split the following lines into separate variables so that I can assign them in separate Excel cells. They are as follows:

Buy or sell:= buy/sell/bot/sold
Quantity := preceded by + or -, 0 to 20 max
Strategy := in between Quantity and Name
Name := before "100". But with one exception, see middle example on /ESU21 which doesn't follow the same pattern
Date : self explanatory
Strike : Between Date and Put / Call
Type : Put or Call or Put/Call
Price : preceded by @

I know how to explain in English, but not in code. Hope someone can guide me along 🙏🏼

So based on the first example, the output should be:

Code: Select all

SOLD
-5
Vertical
VALE
20 Aug 21
21/20
PUT
0.88
Sample Input

Code: Select all

SOLD -5 VERTICAL VALE 100 20 AUG 21 22/20 PUT @.88 CBOE
BUY +1 OKTA 100 20 AUG 21 260 CALL @9.20 LMT MARK
BUY +5 1/-1/1/-1 CUSTOM MU 100 17 SEP 21/17 SEP 21/17 SEP 21/23 JUL 21 80/72.5/67.5/82 CALL/PUT/PUT/CALL @2.25 LMT MARK
BUY +4 DIAGONAL SNOW 100 17 SEP 21/20 AUG 21 260/270 CALL @11.80 LMT MARK
SELL -6 VERTICAL CRSR 100 20 AUG 21 30/27.5 PUT @.85 LMT MARK
SELL -5 IRON CONDOR SPX 100 (Weeklys) 17 SEP 21/17 SEP 21 [AM] 4610/4620/4150/4140 CALL/PUT @3.00 LMT MARK
BUY +5 DBL DIAG FB 100 (Weeklys) 6 AUG 21/30 JUL 21 365/325/365/325 CALL/PUT/CALL/PUT @1.85 LMT MARK
BUY +2 TSM 100 20 JAN 23 120 CALL @16.50 LMT MARK
BOT +1 /ESU21:XCME 1/50 JUL 21 (Monday) (Wk4) /E3AN21:XCME 4285 CALL @12.00
SELL -4 DIAGONAL WKHS 100 (Weeklys) 6 AUG 21/30 JUL 21 9/12 CALL @1.70 LMT
BUY +1 DIAGONAL TSLA 100 17 SEP 21/20 AUG 21 660/675 CALL @23.60 LMT MARK
BUY +3 DIAGONAL V 100 17 SEP 21/20 AUG 21 235/240 CALL @5.45 LMT MARK
BUY +1 CONDOR FVRR 100 17 SEP 21 180/190/200/210 CALL @1.25 LMT MARK
SOLD -1 CONDOR FVRR 100 16 JUL 21 210/230/250/270 CALL @10.20 EDGX
BOT +2 DIAGONAL NFLX 100 17 SEP 21/20 AUG 21 500/520 CALL @16.20 ISE
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: need help on Regexmatch to store multiple variables

07 Aug 2021, 22:05

The issue is that you showed how one example should be parsed, but several of the other lines don’t follow that format. What would you expect the output to be for the third line as one example that has multiple quantities, dates, etc.? What to do about the exception you pointed out? Just skip it? Will there be others that are different in other ways? What other potential surprises might there be that would cause a parsing algorithm to fail? The format isn’t very consistent.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: need help on Regexmatch to store multiple variables

07 Aug 2021, 22:34

Check the source of your data, maybe there is a hidden char or something that separates each and that could be parsed. If not, like boiler said, there is no reliable pattern.
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: need help on Regexmatch to store multiple variables

07 Aug 2021, 22:35

boiler wrote:
07 Aug 2021, 22:05
The issue is that you showed how one example should be parsed, but several of the other lines don’t follow that format. What would you expect the output to be for the third line as one example that has multiple quantities, dates, etc.? What to do about the exception you pointed out? Just skip it? Will there be others that are different in other ways? What other potential surprises might there be that would cause a parsing algorithm to fail? The format isn’t very consistent.
I purposely picked out the most difficult sample examples - those are probably the "edge" cases that we can expect. If I can understand how to parse all these cases, I should be able to do the rest myself.

for the 3ʳᵈ line, it should be parsed as such:

BUY +5 1/-1/1/-1 CUSTOM MU 100 17 SEP 21/17 SEP 21/17 SEP 21/23 JUL 21 80/72.5/67.5/82 CALL/PUT/PUT/CALL @2.25 LMT MARK

Code: Select all

BUY
+5
BBC ; if CUSTOM is spotted and 1/-1/1/-1 precedes it, name it as BBC
MU
17 SEP 21 ; pick the LATEST date out of all dates shown
+80/-72.5/67.5/-82 ; The positive/negative comes from the top:  1/-1/1/-1
CALL/PUT/PUT/CALL
2.25
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: need help on Regexmatch to store multiple variables

07 Aug 2021, 22:36

AHKStudent wrote:
07 Aug 2021, 22:34
Check the source of your data, maybe there is a hidden char or something that separates each and that could be parsed. If not, like boiler said, there is no reliable pattern.
Hi there, there are no hidden characters and the data is pasted as-is. The observable patterns are as described in my 1ˢᵗ and latest post.. not sure if that will suffice.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: need help on Regexmatch to store multiple variables

07 Aug 2021, 22:59

So apparently there is not just a RegEx pattern that would be able to handle all cases. Inside the parsing loop that separates the input into several lines, there would be a bunch of rules that basically follow the direction you provided. You might want to try it and post when you are having trouble. It doesn’t look like teaching aspects of AHK as much as just cranking through the details of your specific requirements. Maybe someone else would enjoy the task.
electrone77
Posts: 16
Joined: 16 Mar 2019, 12:30

Re: need help on Regexmatch to store multiple variables

11 Aug 2021, 16:02

if the start of the pattern is constant: buy/sell/bot/sold

maybe you can mark them with a symbol (e.g. ¢):

Code: Select all

newText := RegexReplace(yourText, "((buy)|(sell)|(bot)|(sold))", "¢$1")
and then you can parse those symbols to get variables using A_LoopField:

Code: Select all

Loop, Parse, newText, ¢
 {
   RegexMatch(A_Loopfield, "....		; might wanna try RegexMatch(A_Loopfield, "s)         as an alternative to ignore newlines
   .
   .
 }

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ArkuS and 342 guests