It is currently April 19th, 2024, 8:55 pm

IfMatch Question

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfMatch Question

Post by jsmorley »

kyriakos876 wrote: December 10th, 2018, 1:29 pm I think he wants an IfMatch that works with 2 conditions.
1) If the RegExp returns nothing, disable MeasureB.
2) If the RegExp return Name1 AND Name2, disable MeasureB.

(don't know the syntax tho so I hope you can fill it from here if that's what he wants.)
Yeah, maybe, but I'm not going to bang my head against this wall until I'm clear what is wanted. This line:

RegExp=(?siU)(?(?=.*<Item>).*<Name1>(.*)</Name2>)

Looks suspicious... You won't see HTML "tags" that don't match like that. If you open a a tag with <Name1>", you have to close it with "</Name1>".

Now maybe the HTML is something like:

<item><Name1>Bob</Name1> loves </Name2>Sue</Name2></item>

But that is not clear to me, and his regular expression doesn't capture the values of Name1 and Name2 separately so they can be tested as individuals. Perhaps he wants to test for the very existence of the literal strings "<Name1>" and "</Name2>", irregardless of what the value(s) might be, or even if they are defined as an empty string like "<Name1></Name1>", but I'm not willing to go down the rabbit hole without a flashlight.

With the example he gives:

Code: Select all

[MeasureA]
Measure=WebParser
Url=#URL#
RegExp=(?siU)(?(?=.*<Item>).*<Name1>(.*)</Name2>)
IfMatch=  |Name1.*Name2
IfMatchAction=[!DisableMeasure "MeasureB"]
There is only a binary outcome possible. Either the literal strings "<Name1>" and "</Name2>" both exist, or the lookahead assertion is untrue and the measure returns an empty string. No complicated test is needed, just test for an empty string, like IfMatch=^$. With his example, there is NO possibility of testing if "<Name1>" exists, but "</Name2>" doesn't.

I need a clear and unambiguous example of what the user is trying to do. We are being expected to put a lot of thought into the answer, I expect a reasonable amount of thought to be put into the question.


Image
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: IfMatch Question

Post by kyriakos876 »

jsmorley wrote: December 10th, 2018, 1:48 pm I need a clear and unambiguous example of what the user is trying to do. We are being expected to put a lot of thought into the answer, I expect a reasonable amount of thought to be put into the question.
Touche.
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: IfMatch Question

Post by balala »

Checking if the returned string is empty, can be done with the IfMAtch=^$ option, not with IfMatch= . Not sure how the source is looking, probably would be great if you could post the URL or the file which you want to parse, but according to the above idea, the complete IfMatch option should probably look like: IfMatch=^$|Name1.*Name2.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfMatch Question

Post by jsmorley »

balala wrote: December 10th, 2018, 2:50 pm Checking if the returned string is empty, can be done with the IfMAtch=^$ option, not with IfMatch= . Not sure how the source is looking, probably would be great if you could post the URL or the file which you want to parse, but according to the above idea, the complete IfMatch option should probably look like: IfMatch=^$|Name1.*Name2.
There is only a binary outcome possible. Either the literal strings "<Name1>" and "</Name2>" both exist, or the lookahead assertion is untrue and the measure returns an empty string. No complicated test is needed, just test for an empty string, like IfMatch=^$. With his example, there is NO possibility of testing if "<Name1>" exists, but "</Name2>" doesn't.
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: IfMatch Question

Post by balala »

jsmorley wrote: December 10th, 2018, 2:51 pm There is only a binary outcome possible. Either the literal strings "<Name1>" and "</Name2>" both exist, or the lookahead assertion is untrue and the measure returns an empty string. No complicated test is needed, just test for an empty string, like IfMatch=^$. With his example, there is NO possibility of testing if "<Name1>" exists, but "</Name2>" doesn't.
Nor me don't exactly know what he wants, was just a thought. We have to wait probably for some details.
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: IfMatch Question

Post by balala »

Or a new idea would be to create a String measure, which joins together the two strings and makes the needed test:

Code: Select all

[MeasureRainmeter]
Measure=WebParser
UpdateRate=900
Url=#URL#
RegExp=(?siU)(?(?=.*<Item>).*<Name1>(.*)</Name1>.*<Name2>(.*)</Name2>)

[MeasureA]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=1

[MeasureB]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=2

[MeasureString]
Measure=String
String=[MeasureA][MeasureB]
IfMatch=^$|Name1Name2
IfMatchAction=[!DisableMeasure "MeasureB"]
DynamicVariables=1
The above IfMatchAction disables the [MeasureB] measure either if none of the names exist, or if both exist and are those added into the IfMatch option.
But still not sure if this is what xenium wants.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfMatch Question

Post by jsmorley »

balala wrote: December 10th, 2018, 3:13 pm Or a new idea would be to create a String measure, which joins together the two strings and makes the needed test:

Code: Select all

[MeasureRainmeter]
Measure=WebParser
UpdateRate=900
Url=#URL#
RegExp=(?siU)(?(?=.*<Item>).*<Name1>(.*)</Name1>.*<Name2>(.*)</Name2>)

[MeasureA]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=1

[MeasureB]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=2

[MeasureString]
Measure=String
String=[MeasureA][MeasureB]
IfMatch=^$|Name1Name2
IfMatchAction=[!DisableMeasure "MeasureB"]
DynamicVariables=1
The above IfMatchAction disables the [MeasureB] measure either if none of the names exist, or if both exist and are those added into the IfMatch option.
But still not sure if this is what xenium wants.
Yes, although the regular expression would have to be a bit more complicated than that. What you have is still "binary". They either both exist, or nothing is returned. You would need something like:

RegExp=(?siU)<item>(?(?=.*<Name1>).*<Name1>(.*)</Name1>)(?(?=.*<Name2>).*<Name2>(.*)</Name2>).*</item>
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: IfMatch Question

Post by balala »

jsmorley wrote: December 10th, 2018, 3:21 pm What you have is still "binary". They either both exist, or nothing is returned.
Yes, it is, but xenium in his request said:
xenium wrote: December 10th, 2018, 12:54 pm I want that when in RegExp is the name1 together with the name2, or the entire RegExp is missing, be disabled MeasureB.
That's why I checked if none or both strings exist.
Maybe I'm wrong... :confused:
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfMatch Question

Post by jsmorley »

balala wrote: December 10th, 2018, 3:36 pm Yes, it is, but xenium in his request said:

That's why I checked if none or both strings exist.
Maybe I'm wrong... :confused:
But the logic of what he said means that if Name1 alone exists, it should not disable the measure. Your regular expression can't return only Name1.

BTW, I think I would need to amend my regular expression above, to account for no <item> at all, so there isn't an error in the log...

RegExp=(?siU)(?(?=<item>)<item>(?(?=.*<Name1>).*<Name1>(.*)</Name1>)(?(?=.*<Name2>).*<Name2>(.*)</Name2>))

It all still falls apart of course, since his description seems to indicate that he is interested in ANY value for what is in <Name1> and <Name2>, and just concatenating the two child measures won't get you there... "Bob", "Sue" and "BobSue" all create an IfMatch that succeeds, with no distinction.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfMatch Question

Post by jsmorley »

You would almost need something like this:

Code: Select all

[Rainmeter]
Update=100
AccurateText=1
DynamicWindowSize=1
MouseActionCursor=0

[Variables]
MatchCount=0

[MeasureFile]
Measure=WebParser
URL=file://#CURRENTPATH#Test.xml
RegExp=(?siU)(?(?=<item>)<item>(?(?=.*<Name1>).*<Name1>(.*)</Name1>)(?(?=.*<Name2>).*<Name2>(.*)</Name2>))
FinishAction=[!SetVariable MatchCount "0"]

[MeasureName1]
Measure=WebParser
URL=[MeasureFile]
StringIndex=1
DynamicVariables=1
IfMatch=^(?!\s*$)(.*)
IfMatchAction=[!SetVariable MatchCount "(#MatchCount#+1)"]

[MeasureName2]
Measure=WebParser
URL=[MeasureFile]
StringIndex=2
DynamicVariables=1
IfMatch=^(?!\s*$)(.*)
IfMatchAction=[!SetVariable MatchCount "(#MatchCount#+1)"]
IfCondition=#MatchCount# = 0
IfTrueAction=[!DisableMeasure SomeMeasure]
IfCondition2=#MatchCount# = 1
IfTrueAction2=[!EnableMeasure SomeMeasure]
IfCondition3=#MatchCount# = 2
IfTrueAction3=[!DisableMeasure SomeMeasure]

[SomeMeasure]
Measure=Calc
Formula=SomeMeasure + 1

[MeterResult]
Meter=String
MeasureName=SomeMeasure
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
That is based on an XML like:

Code: Select all

<item>
<Name1>Bob</Name1>
<Name2>Sue</Name2>
</item>

Although to be honest, I'd be jumping to Lua for this long before I got to that point... Even this has logic issues if <Name2> exists but <Name1> doesn't.