It is currently April 25th, 2024, 9:16 am

parsing single expression trouble [Solved x3]

Get help with creating, editing & fixing problems with skins
User avatar
Mor3bane
Posts: 943
Joined: May 7th, 2016, 7:32 am

parsing single expression trouble [Solved x3]

Post by Mor3bane »

Hi,

Parsing is everyone's weak spot, since there are so many bits to it.

I am hoping for help parsing a single expression:

<dnam>Mount Isa, QNS, Australia</dnam>

The RegExp looks like this at the moment:
"(?siU)<ut>(.*)</ut>.*<dnam>(.*)</dnam>.*<hi>(.*)</hi>.*<low>(.*)</low>"

Can <dnam> be RegExp'd to just say "Mount Isa, QNS"? (without the quotes :) )

Thnanks for any help
Last edited by Mor3bane on December 31st, 2016, 10:11 pm, edited 1 time in total.
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it

The law of averages says what it means; even if you get everything right, you will get something wrong. Therefore; self managing error trapping initiates another set of averages - amongst the errors, some of them will not be errors, instead those instances will appear to be "luck". One cannot complain of the 'appearance' of 'infinite regress of causation', even if it does not have a predictable pattern, only that it requires luck to achieve.
User avatar
fonpaolo
Moderator
Posts: 1387
Joined: April 11th, 2013, 8:08 pm
Location: Italy

Re: parsing single expression trouble

Post by fonpaolo »

Try this: (?siU).*<dnam>(.*), Australia.*
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: parsing single expression trouble

Post by balala »

Or another solution would be to get the whole string, then use a properly set substitution to get the needed parts of the string:

Code: Select all

[MeasureLocation]
Measure=Plugin
Plugin=WebParser
UpdateRate=900
Url=The proper URL
RegExp=(?siU)<dnam>(.*)</dnam>
StringIndex=1
RegExpSubstitute=1
Substitute="^(.*), (.*), (.*)$":"\1, \2"
The WebParser plugin measure will get the Mount Isa, QNS, Australia string, and the substitution will remove the last string (in this case the Australia), leaving just the two strings before the last comma (in this case Mount Isa, QNS).
This solution will work for any string with three sections, separated by two commas, even if the last string is not Australia.
User avatar
Mor3bane
Posts: 943
Joined: May 7th, 2016, 7:32 am

Re: parsing single expression trouble

Post by Mor3bane »

fonpaolo wrote:Try this: (?siU).*<dnam>(.*), Australia.*
Thanks fonpaolo - incidentally the "." at the end could be misconstrued as part of the RegExp example :???: :)
balala wrote:Substitute="^(.*), (.*), (.*)$":"\1, \2"

The WebParser plugin measure will get the Mount Isa, QNS, Australia string, and the substitution will remove the last string (in this case the Australia), leaving just the two strings before the last comma (in this case Mount Isa, QNS).
This solution will work for any string with three sections, separated by two commas, even if the last string is not Australia.
Thanks balala - I tried a version of that, so thanks for the correct syntax. :great:
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it

The law of averages says what it means; even if you get everything right, you will get something wrong. Therefore; self managing error trapping initiates another set of averages - amongst the errors, some of them will not be errors, instead those instances will appear to be "luck". One cannot complain of the 'appearance' of 'infinite regress of causation', even if it does not have a predictable pattern, only that it requires luck to achieve.
User avatar
Mor3bane
Posts: 943
Joined: May 7th, 2016, 7:32 am

Re: parsing single expression trouble

Post by Mor3bane »

Hi again,

I just realised, that whilst fonpaolo's version works as part of the RegExp, balala'a will only work for the single expression in a Substitute parameter.

So, sort of both are not very portable or incorporative for this instance.

Not sure how to get both benefits without the drawbacks.

What I mean to ask, is there a way to modify the RegExp like fonpaolo with a syntax as versatile as balala's example?

Any suggestions?

Thanks
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it

The law of averages says what it means; even if you get everything right, you will get something wrong. Therefore; self managing error trapping initiates another set of averages - amongst the errors, some of them will not be errors, instead those instances will appear to be "luck". One cannot complain of the 'appearance' of 'infinite regress of causation', even if it does not have a predictable pattern, only that it requires luck to achieve.
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: parsing single expression trouble

Post by balala »

I'm not sure I understood what you mean by
Mor3bane wrote:will only work for the single expression in a Substitute parameter.
but maybe something like this could help:

Code: Select all

[MeasureLocation]
Measure=Plugin
Plugin=WebParser
UpdateRate=900
Url=Enter the desired URL
RegExp=(?siU)<dnam>(.*), (.*), (.*)</dnam>

[MeasureLocationCity]
Measure=Plugin
Plugin=WebParser
Url=[MeasureLocation]
StringIndex=1

[MeasureLocationState]
Measure=Plugin
Plugin=WebParser
Url=[MeasureLocation]
StringIndex=2

[MeasureLocationCountry]
Measure=Plugin
Plugin=WebParser
Url=[MeasureLocation]
StringIndex=3
In this case, the [MeasureLocationCity] measure will get the string before the first comma, [MeasureLocationState] that between the two commas, while [MeasureLocationCountry] will get the last string, placed after the last comma (I hope I named correctly those strings, if not, you can rename them).
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: parsing single expression trouble

Post by FreeRaider »

Another RegExp option

Code: Select all

(?siU)<dnam>(.*)\W+\s+(.*)\W+\s+\w+<\/dnam>
User avatar
Mor3bane
Posts: 943
Joined: May 7th, 2016, 7:32 am

Re: parsing single expression trouble

Post by Mor3bane »

balala wrote:I'm not sure I understood what you mean by

but maybe something like this could help:

Code: Select all

[MeasureLocation]
Measure=Plugin
Plugin=WebParser
UpdateRate=900
Url=Enter the desired URL
RegExp=(?siU)<dnam>(.*), (.*), (.*)</dnam>

[MeasureLocationCity]
Measure=Plugin
Plugin=WebParser
Url=[MeasureLocation]
StringIndex=1

[MeasureLocationState]
Measure=Plugin
Plugin=WebParser
Url=[MeasureLocation]
StringIndex=2

[MeasureLocationCountry]
Measure=Plugin
Plugin=WebParser
Url=[MeasureLocation]
StringIndex=3
In this case, the [MeasureLocationCity] measure will get the string before the first comma, [MeasureLocationState] that between the two commas, while [MeasureLocationCountry] will get the last string, placed after the last comma (I hope I named correctly those strings, if not, you can rename them).
Ah ok, I see that RegExp works in line (terminology?).

However, this is the RegExp I am currently referencing my String Indexes from:
"(?siU)<ut>(.*)</ut>.*<dnam>(.*)</dnam>.*<hi>(.*)</hi>.*<low>(.*)</low>", so I am not sure how to String Index this:
"(?siU)<ut>(.*)</ut>.*<dnam>(.*), (.*), (.*)</dnam>.*<hi>(.*)</hi>.*<low>(.*)</low>"
I appreciate this as I am learning from as much of these helps as I can :)
Last edited by Mor3bane on December 31st, 2016, 9:48 pm, edited 1 time in total.
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it

The law of averages says what it means; even if you get everything right, you will get something wrong. Therefore; self managing error trapping initiates another set of averages - amongst the errors, some of them will not be errors, instead those instances will appear to be "luck". One cannot complain of the 'appearance' of 'infinite regress of causation', even if it does not have a predictable pattern, only that it requires luck to achieve.
User avatar
Mor3bane
Posts: 943
Joined: May 7th, 2016, 7:32 am

Re: parsing single expression trouble

Post by Mor3bane »

FreeRaider wrote:Another RegExp option

Code: Select all

(?siU)<dnam>(.*)\W+\s+(.*)\W+\s+\w+<\/dnam>
This is nice.
Mostly since I have another weather realted meter that has the full dnam expression defined in full.
The meter this will be applied to is a temperature high/low monitor, so the simple town/city should suffice.

Thanks :great:
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it

The law of averages says what it means; even if you get everything right, you will get something wrong. Therefore; self managing error trapping initiates another set of averages - amongst the errors, some of them will not be errors, instead those instances will appear to be "luck". One cannot complain of the 'appearance' of 'infinite regress of causation', even if it does not have a predictable pattern, only that it requires luck to achieve.
User avatar
Mor3bane
Posts: 943
Joined: May 7th, 2016, 7:32 am

Re: parsing single expression trouble

Post by Mor3bane »

OOOOH!!

Ok, I think I just figured something out:

For every (.*) there will increment another StringIndex

Yes?

Well, seems to work that way in my first test.
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it

The law of averages says what it means; even if you get everything right, you will get something wrong. Therefore; self managing error trapping initiates another set of averages - amongst the errors, some of them will not be errors, instead those instances will appear to be "luck". One cannot complain of the 'appearance' of 'infinite regress of causation', even if it does not have a predictable pattern, only that it requires luck to achieve.