MazinLabib10 wrote: ↑May 26th, 2023, 7:05 pm
Oh don't worry! I actually removed the edit because I'd found a fix for it and I didn't think you'd have seen it already. However, what you've suggested now is so much more efficient than what I came up with. So thanks a lot!
Yeah, I noticed both the original and your edit, but I'm not one to let stuff linger around. In fact, here's another method, also efficient, which instead of using WebParser's StringIndex, relies on getting the entire file contents and removing everything but the matching club names, transforming the data into a comma separated list, on which it then computes the number of elements, and finally iterates through each of its elements, also by scrolling:
Code: Select all
[Variables]
ClubCount=0
ClubIndex=0
ClubName=fc
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
---Measures---
[Clubs]
Measure=WebParser
URL=file://#@#Clubs.txt
RegExp=(?siU)^(.*)$
UpdateRate=-1
RegExpSubstitute=1
Substitute="(?siU).*(?:\R(\N*#ClubName#\N*) \/|$)":"\1,","\\1,":""
FinishAction=[!UpdateMeasureGroup ClubGroup][!UpdateMeter Result][!Redraw]
DynamicVariables=1
[Count]
Group=ClubGroup
Measure=String
String=[Clubs]
UpdateDivider=-1
RegExpSubstitute=1
Substitute="(?siU).*,":"+1","^$":"0"
OnUpdateAction=[!SetVariable ClubCount ([Count])]
DynamicVariables=1
[Club]
Group=ClubGroup
Measure=String
String=[Clubs]
UpdateDivider=-1
RegExpSubstitute=1
Substitute="(?siU)^(?:(?:.*,){0,#ClubIndex#}+(.*),.*|.*)$":"\1","\\1":""
DynamicVariables=1
---Meters---
[Result]
Meter=String
SolidColor=0,0,0,128
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
AntiAlias=1
MeasureName=Club
Text=Club Found #ClubIndex# = %1
UpdateDivider=-1
MouseScrollUpAction=[!SetVariable ClubIndex (Clamp(#ClubIndex#-1,0,#ClubCount#?#ClubCount#-1:0))][!UpdateMeasure Club][!UpdateMeter Result][!Redraw]
MouseScrollDownAction=[!SetVariable ClubIndex (Clamp(#ClubIndex#+1,0,#ClubCount#?#ClubCount#-1:0))][!UpdateMeasure Club][!UpdateMeter Result][!Redraw]
DynamicVariables=1
Creating the list is based on the same regex pattern as before (no conditional needed this time), with the help of which we retain the captures (enclosed by plain round brackets and referenced by \1) and add commas after them, in effect deleting the parts before the searched string matches and up to the end of the string (i.e. parts that are to the left, between, and to the right of the matches), and finally removing the literal "\1" leftovers if any.
Counting the elements in the list is based on simply replacing each element followed by a comma with "+1", handling the empty string exception case with the help of "0", then converting the "+1+1..." string into a numerical formula by enclosing it between round brackets when we set the ClubCount variable.
Picking the ClubIndex-th element (with the index starting at 0 and not 1 this time) is done by using (?:) to skip the first ClubIndex elements via (?:.*,){0,#ClubIndex#}+ where we used {quantifiers}, capturing the following element by enclosing it between plain round brackets, and ignoring the rest (or, via |.*, everything, if nothing is captured). We again retain only the capture, in effect discarding the rest, remove the literal "\1" leftovers if any, and we're done.
When scrolling, we clamp / limit the index between 0 and ClubCount-1 (unless ClubCount is 0, in which case we don't use -1 but 0 as the upper limit) by using numerical conditionals.
One advantage of this approach is that you don't need to create N measures, each with its own StringIndex, to get the found string matches, a single measure is enough. Another advantage is that, since we don't need to create N measures, we are not limited by N anymore, so we can iterate through a theoretically (but not practically, since regex has also some limits, of course much larger) unlimited number of matches, if we wanted to.
References:
- most of the regex details are found in the RegEx Reference (a few lines in the Groups And References + Quantifiers And Alternation topics) sidebar on the leftside of the RegExR.com page I screenshot before
-
numerical conditionals in Rainmeter formulas
- the rest is just a bit of creativity to get what one needs