Is there a way to Regex a Regex?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Haduis
Newbie
Posts: 5
Joined: Wed Oct 16, 2013 5:23 am

Is there a way to Regex a Regex?

Post by Haduis » Sun Mar 16, 2014 4:24 am

Basically, I'm putting a chatlog through Regex to parse individual portions into an array.

Then I want to be able to search these arrays, and if they have what I'm searching for, I want to output the information. If they don't have what I'm searching for, I want to discard them.

The part I'm stuck on right now is that the first Regex puts everything into an array (matches_array_1,matches_array_2,matches_array3,etc)

Then I'm using:

Let>k=0
Label>Loop
Let>k=k+1
Let>TextVariables=matches_array_%k%
if>%k%=%num_matches%,End,Loop

To let the TextVariables variable change its value within a loop to match the initial Regex's num_matches so it knows when to stop.

Is there a better way to do this?

Code: Select all

wait>5
Let>INPUT_BROWSE=1
Input>DelveFileName,Find the delve file you want to parse.,C:DelveTest.txt

ReadFile>C:DelveTest.txt,strFileContents



Let>pattern=(?s)\[\d\d:\d\d:\d\d\] <Begin Info:.*?<End>
regex>pattern,%strFileContents%,0,matches_array,num_matches,0



Input>Input2,What stat would you like to parse for?,.*
Let>k=0

Label>Loop
Let>k=k+1
Let>TextVariables=matches_array_%k%
Let>pattern2=(?is)\[\d\d:\d\d:\d\d\] <Begin Info:.*?%Input2%.*?<End>
regex>pattern2,TextVariables,0,matches_array2,num_matches2,0

if>%k%=%num_matches%,End,Loop

Label>End

Haduis
Newbie
Posts: 5
Joined: Wed Oct 16, 2013 5:23 am

Post by Haduis » Sun Mar 16, 2014 5:32 am

Oh, and here's an example of 3 of the chat logged items.

I want to be able to search for individual attributes (like Strength, Body, Piety, Duration etc.) and then throw away the items that don't have those stats.

Begin Info and End Info are the start and end points of each item.

Code: Select all

[18:34:49] <Begin>
[18:34:49] Unique Object
[18:34:49]  
[18:34:49]  
[18:34:49] Magical Bonuses:
[18:34:49] - Piety: 12 pts
[18:34:49] - Body: 8%
[18:34:49] - Power: 7 % of power pool.
[18:34:49]  
[18:34:49] Bonus to duration of spells: 16%
[18:34:49]  
[18:34:49]  
[18:34:49] Bonus Level: 0
[18:34:49] <End>
[18:34:52] <Begin>
[18:34:52] Unique Object
[18:34:52]  
[18:34:52]  
[18:34:52] Magical Bonuses:
[18:34:52] - Power: 11 % of power pool.
[18:34:52] - Instruments: 2 pts
[18:34:52] - Strength: 21 pts
[18:34:52]  
[18:34:52] Bonus to duration of spells: 15%
[18:34:52]  
[18:34:52]  
[18:34:52] Bonus Level: 0
[18:34:52] <End>
[18:34:53] <Begin>
[18:34:53] Unique Object
[18:34:53]  
[18:34:53]  
[18:34:53] Magical Bonuses:
[18:34:53] - Strength: 16 pts
[18:34:53] - Power: 8 % of power pool.
[18:34:53]  
[18:34:53] Bonus to armor factor (AF): 14
[18:34:53] Bonus to duration of spells: 15%
[18:34:53]  
[18:34:53]  
[18:34:53] Bonus Level: 0
[18:34:53] <End>

Haduis
Newbie
Posts: 5
Joined: Wed Oct 16, 2013 5:23 am

Post by Haduis » Sun Mar 16, 2014 6:56 am

Never mind! I was expecting it to take one input at a time and give me three outputs!

Brain fart.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts