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
It is currently April 25th, 2024, 9:16 am
parsing single expression trouble [Solved x3]
-
- Posts: 943
- Joined: May 7th, 2016, 7:32 am
parsing single expression trouble [Solved x3]
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.
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.
-
- Moderator
- Posts: 1387
- Joined: April 11th, 2013, 8:08 pm
- Location: Italy
-
- Rainmeter Sage
- Posts: 16168
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: parsing single expression trouble
Or another solution would be to get the whole string, then use a properly set substitution to get the needed parts of the string:
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.
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"
This solution will work for any string with three sections, separated by two commas, even if the last string is not Australia.
-
- Posts: 943
- Joined: May 7th, 2016, 7:32 am
Re: parsing single expression trouble
Thanks fonpaolo - incidentally the "." at the end could be misconstrued as part of the RegExp examplefonpaolo wrote:Try this: (?siU).*<dnam>(.*), Australia.*
Thanks balala - I tried a version of that, so thanks for the correct syntax.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.
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.
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.
-
- Posts: 943
- Joined: May 7th, 2016, 7:32 am
Re: parsing single expression trouble
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
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.
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.
-
- Rainmeter Sage
- Posts: 16168
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: parsing single expression trouble
I'm not sure I understood what you mean by
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).
but maybe something like this could help:Mor3bane wrote:will only work for the single expression in a Substitute parameter.
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
-
- Posts: 826
- Joined: November 20th, 2012, 11:58 pm
Re: parsing single expression trouble
Another RegExp option
Code: Select all
(?siU)<dnam>(.*)\W+\s+(.*)\W+\s+\w+<\/dnam>
-
- Posts: 943
- Joined: May 7th, 2016, 7:32 am
Re: parsing single expression trouble
Ah ok, I see that RegExp works in line (terminology?).balala wrote:I'm not sure I understood what you mean by
but maybe something like this could help: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).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
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.
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.
-
- Posts: 943
- Joined: May 7th, 2016, 7:32 am
Re: parsing single expression trouble
This is nice.FreeRaider wrote:Another RegExp option
Code: Select all
(?siU)<dnam>(.*)\W+\s+(.*)\W+\s+\w+<\/dnam>
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
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.
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.
-
- Posts: 943
- Joined: May 7th, 2016, 7:32 am
Re: parsing single expression trouble
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.
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.
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.