It is currently April 19th, 2024, 4:27 pm

Help with RegEx in WebParser please?

Get help with creating, editing & fixing problems with skins
User avatar
JayOtt
Posts: 14
Joined: February 19th, 2019, 2:15 pm

Help with RegEx in WebParser please?

Post by JayOtt »

Hi all!

So I have WebParser pointed at a site which just shows data like this:

Code: Select all

joeblogs,5370,726,0,0,0,0,0,0,0,0
johndoe,3930,0,0,0,0,0,0,0,0,2345
gijane,7199,0,2938,681,0,0,0,343,0,45
fredbloggs,5515,1106,0,0,0,0,0,0,0,0
billybigears,7087,902,4075,0,0,0,0,0,0,0
etc etc
... and I'm trying to figure out how I can form the RegEx to capture just one of these lines, starting with the name and ending at the end of the line.

I have a [MeasureUser] that gives us johndoe, so;

Code: Select all

RegExp=(?siU)[MeasureUser],(.*),.*(.*),.*(.*),.*(.*),.*(.*),.*(.*),.*(.*),.*(.*),.*(.*),.*(.*)$
... should work properly, right? But the Rainmeter logs are just throwing RegEx errors on every refresh.

I'm assuming it's where I'm trying to stop it capturing on the new line... so how does Rainmeter want me to handle that?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with RegEx in WebParser please?

Post by jsmorley »

Yes, the $ character will signify the end of the entire string, not the end of a line. Also, don't forget DynamicVariables=1 since you are using a [SectionVariable] in the RegExp.

You want:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureUser]
Measure=String
String=fredbloggs

[MeasureFile]
Measure=WebParser
URL=file://#CURRENTPATH#Test.html
RegExp=(?siU)[MeasureUser],(.*),.*(.*),.*(.*),.*(.*),.*(.*),.*(.*),.*(.*),.*(.*),.*(.*),.*(.*)\r\n
DynamicVariables=1

[MeasureUser10thItem]
Measure=WebParser
URL=[MeasureFile]
StringIndex=10

[MeterUser10thItem]
Meter=String
MeasureName=MeasureUser10thItem
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
1.jpg


Test.html:

Code: Select all

joeblogs,5370,726,0,0,0,0,0,0,0,0
johndoe,3930,0,0,0,0,0,0,0,0,2345
gijane,7199,0,2938,681,0,0,0,343,0,45
fredbloggs,5515,1106,0,0,0,0,0,0,0,87
billybigears,7087,902,4075,0,0,0,0,0,0,0


Note, the \r\n is carriage return / linefeed. This assumes it has that end-of-line sequence in the source. If not, and it is possible, maybe likely, that it doesn't, then just use \n alone.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with RegEx in WebParser please?

Post by balala »

EDIT: Sorry jsmorley.

Try the following RegExp: RegExp=(?siU)([MeasureUser].*)\n, adding the DynamicVariables=1 option as well.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with RegEx in WebParser please?

Post by jsmorley »

Yes, although the $ at the end won't give you the desired result, as it will capture everything from the "87" in my example to the end of the entire stream in that 10th (capture), it is the lack of DynamicVariables=1 that is actually causing the regular expression error. Without that, the section variable [MeasureUser] has no value.
User avatar
JayOtt
Posts: 14
Joined: February 19th, 2019, 2:15 pm

Re: Help with RegEx in WebParser please?

Post by JayOtt »

Thanks jsmorley.

Hmm, with that RegEx Rainmeter is now not parsing anything and giving me "RegExp matching error (-8)" instead.

Ah, but using just \n instead of \r\n has worked a treat. Thanks! :D

I'm still getting errors, but that's just because the source URL occasionally refreshes with a "java.lang.OutOfMemoryError: Java heap space" error and I guess Rainemeter doesn't know what to do with that. The URL is beyond my control unfortunately, so it'll have to do.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with RegEx in WebParser please?

Post by jsmorley »

JayOtt wrote: February 26th, 2019, 2:05 pm Thanks jsmorley.

Hmm, with that RegEx Rainmeter is now not parsing anything and giving me "RegExp matching error (-8)" instead.

Ah, but using just \n instead of \r\n has worked a treat. Thanks! :D

I'm still getting errors, but that's just because the source URL occasionally refreshes with a "java.lang.OutOfMemoryError: Java heap space" error and I guess Rainemeter doesn't know what to do with that. The URL is beyond my control unfortunately, so it'll have to do.
Yeah, constructing something that would react gracefully to that error condition would be challenging, as it would require hitting the site twice. Once to test for that condition with IfMatch, and having that !EnableMeasure the real one that gets the data. This would be hard, as IfMatch is a binary. It either matches or it doesn't, and all WebParser measures return an initial empty string "" which "won't match" the error you are testing for, and it will assume success... Once you have "enabled" the real WebParser measure, the horse is out of the barn.
User avatar
JayOtt
Posts: 14
Joined: February 19th, 2019, 2:15 pm

Re: Help with RegEx in WebParser please?

Post by JayOtt »

Are we able to turn off error reporting for a particular command or meter?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with RegEx in WebParser please?

Post by jsmorley »

JayOtt wrote: February 26th, 2019, 2:26 pm Are we able to turn off error reporting for a particular command or meter?
No. The only error condition you can turn off is "Not enough substrings", which is not really relevant to this situation. If the parent measure fails, the children are never updated and won't produce their own errors.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with RegEx in WebParser please?

Post by jsmorley »

I think you could construct something that tests for that error and sets the Text values of meters to something like "N/A" if you want, or even just hides them, but I don't see a way to avoid the regular expression error showing up in the log. That's a temporary (presumably) and non-fatal error, so I think it's best to just ignore it.

To be honest, since this is a transitory error, I'd be tempted not to alter the meters. They will just keep their old values until the condition corrects itself and then will change to the new ones. It's all visibly seamless.

If you really want the skin to react to it, I'd be more tempted to have some little ! icon or something be hidden / unhidden based on the state of the error.

But the long and the short of it is that any "failure" of a WebParser parent measure WILL produce an error in the log.
User avatar
JayOtt
Posts: 14
Joined: February 19th, 2019, 2:15 pm

Re: Help with RegEx in WebParser please?

Post by JayOtt »

It's all good; I've made the actual meter ignore the service interruptions with a kinda buffer Measure using Calc.

Code: Select all

[MeasureUser10thItemPre]
Measure=WebParser
URL=[MeasureFile]
StringIndex=10

;Measure buffer thing
[MeasureUser10thItem]
Measure=Calc
Formula=MeasureUser10thItemPre

[MeterUser10thItem]
Meter=String
MeasureName=MeasureUser10thItem
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
... and so if for whatever reason WebParser doesn't get anything useful from the URL, it still displays whatever that calculation was last. :D
Last edited by JayOtt on February 26th, 2019, 2:52 pm, edited 1 time in total.