Hi guys,
I found the data source I'd been searching for for ages, which has a long list of numerical values separated only by whitespace. Through detective work I've managed to figure out which number represents which variable, so now I just need some help in writing the regular expressions to parse this... the item is http://www.sheffieldweather.co.uk/meso2/clientraw.txt.
Just to clarify, I need to know what RegExp to write to read, say, the 5th value from the right (which I know is temperature) and assign it to a variable. The tutorials on the site are great but as far as I can find have no mention of using whitespace as delimiters...
It is currently April 27th, 2024, 11:22 pm
Help needed with RegExps counting whitespaces...
-
- Posts: 41
- Joined: September 22nd, 2011, 1:03 pm
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Help needed with RegExps counting whitespaces...
It's really easy.
RegExp="(?siU)(.*) (.*) (.*) (.*) (.*) "
Using spaces to indicate the end of each "capture", that would give you the first five items from that long string. Just keep adding to it as needed.
Now, the "catch"... WebParser will only return 99 or fewer StringIndexes in any single measure. There are 174 items in that string. So you need to pick and choose a bit to keep it under 99 "captures". The way you do that is:
RegExp="(?siU)(.*) (.*) (.*) (.*) (.*) .* (.*) "
That would get the first five, then skip the sixth and get the seventh. The difference is that (.*) mean "capture" and .* (without the parens) means "skip". I assume you need only a handful of the items in this string, so just use (.*) for the ones you want, and .* for the ones you don't need.
Hope this helps.
RegExp="(?siU)(.*) (.*) (.*) (.*) (.*) "
Using spaces to indicate the end of each "capture", that would give you the first five items from that long string. Just keep adding to it as needed.
Now, the "catch"... WebParser will only return 99 or fewer StringIndexes in any single measure. There are 174 items in that string. So you need to pick and choose a bit to keep it under 99 "captures". The way you do that is:
RegExp="(?siU)(.*) (.*) (.*) (.*) (.*) .* (.*) "
That would get the first five, then skip the sixth and get the seventh. The difference is that (.*) mean "capture" and .* (without the parens) means "skip". I assume you need only a handful of the items in this string, so just use (.*) for the ones you want, and .* for the ones you don't need.
Hope this helps.
-
- Posts: 41
- Joined: September 22nd, 2011, 1:03 pm
Re: Help needed with RegExps counting whitespaces...
Hmm... that does look simple... so I tried to implement it;
However, this gives me an output of "Temperature: 12345 3.5 5.2 155 %" which is the first 4 items (which I don't need) and seems to convert the fifth value, the one I want, into a % sign...
And yeah, I won't need more than 1 value per measure, so I definitely won't exceed the 99 limit, since I'll have to do a different RegExp per measure...
Code: Select all
;----------------MEASURES------------------
[MeasureActualTemp]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=2
Url=http://www.sheffieldweather.co.uk/meso2/clientraw.txt
RegExp="(?siU).* .* .* .* (.*)"
;----------------METERS--------------------
[MeterTempText]
Meter=String
MeasureName=MeasureActualTemp
X=5
Y=5
W=300
H=100
FontColor=#Colour2#
Text="Temperature: %1%"
AntiAlias=1
And yeah, I won't need more than 1 value per measure, so I definitely won't exceed the 99 limit, since I'll have to do a different RegExp per measure...
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Help needed with RegExps counting whitespaces...
You are missing the final space before the end quote.
I get 16.2 as the return.
I get 16.2 as the return.
-
- Posts: 41
- Joined: September 22nd, 2011, 1:03 pm
Re: Help needed with RegExps counting whitespaces...
Adding the final space added 16.2 to the end of my long string... however for whatever reason the other values are still there, along with a % sign... it's confusing :/
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Help needed with RegExps counting whitespaces...
If you are only getting one "capture" in the measure, add
StringIndex=1
To the WebParser measure.
StringIndex=1
To the WebParser measure.
-
- Posts: 41
- Joined: September 22nd, 2011, 1:03 pm
Re: Help needed with RegExps counting whitespaces...
Ahh there we go... that solved it thanks . What's the mechanics behind the StringIndex=1 statement? Also the extra % sign was a relic from the code I took the Text= bit from, fixed that up.
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Help needed with RegExps counting whitespaces...
The way WebParser works, is that it creates what in effect is an array of values called StringIndex. This will have as many entries as there are "captures" (.*) in your RegExp= statement. So if you have:Kyremi wrote:Ahh there we go... that solved it thanks . What's the mechanics behind the StringIndex=1 statement? Also the extra % sign was a relic from the code I took the Text= bit from, fixed that up.
RegExp="(?siU).*<title>(.*)</title>.*<author>(.*)</author>"
You will have 2 StringIndexes. One will point to the value you returned for "title" and the other for the value you returned for "author".
Now, to "use" those values in meters, you need a way to "pick off" each value one at a time. The way we do this is with a "parent / child" capability built into WebParser:
[MainMeasure]
Measure=Plugin
Plugin=WebParser.dll
URL=http://SomeSite.com
RegExp="(?siU).*<title>(.*)</title>.*<author>(.*)</author>"
[TitleChildMeasure]
Measure=Plugin
Plugin=WebParser.dll
URL=[MainMeasure]
StringIndex=1
[AuthorChildMeasure]
Measure=Plugin
Plugin=WebParser.dll
URL=[MainMeasure]
StringIndex=2
[TitleMeter]
Meter=String
MeasureName=TitleChildMeasure
[AuthorMeter]
Meter=String
MeasureName=AuthorChildMeasure
See how that works? Now, since you only had one capture in your measure, it was fine to just put the StringIndex=1 right on it.
-
- Posts: 41
- Joined: September 22nd, 2011, 1:03 pm
Re: Help needed with RegExps counting whitespaces...
Odd thing just happened... I was expanding my code to read the variables I wanted, when suddenly on a refresh I wasn't getting any values at all, it just stopped reading anything. Could it be my refresh rate of 1 second was too high for the server and it auto-blocked me? I can still access the URL from my browser though so I'm not sure if that's the case... I've changed the update rate to 5000 now, but it's still blank... I checked the Values tab in Manage Rainmeter and they're all blank...
Here's the code in case I've managed to do anything insanely wrong...
Here's the code in case I've managed to do anything insanely wrong...
Code: Select all
[Rainmeter]
Update=5000
Author=Kyremi
BackgroundMode=2 ;1 = transparent, 2 = solid colour.
SolidColor=#Colour1#
[Metadata]
Name=
Information=
License=
Version=
[Variables]
Colour1=32,32,32,125
Colour2=255,255,255,255
Colour3=0,0,0,128
Colour4=0,0,0,0
Colour5=255,255,255,120
Colour6=255,0,0,255
Colour7=255,0,0,128
StartAngle=-1.570796
;----------------MEASURES------------------
[MeasureActualTemp]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url=http://www.sheffieldweather.co.uk/meso2/clientraw.txt
RegExp="(?siU).* .* .* .* (.*) "
StringIndex=1
[MeasureActualHumidity]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url=http://www.sheffieldweather.co.uk/meso2/clientraw.txt
RegExp="(?siU).* .* .* .* .* (.*) "
StringIndex=1
[MeasureActualPressure]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url=http://www.sheffieldweather.co.uk/meso2/clientraw.txt
RegExp="(?siU).* .* .* .* .* .* (.*) "
StringIndex=1
[MeasureActualDailyRain]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url=http://www.sheffieldweather.co.uk/meso2/clientraw.txt
RegExp="(?siU).* .* .* .* .* .* .* (.*) "
StringIndex=1
[MeasureActualMonthlyRain]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url=http://www.sheffieldweather.co.uk/meso2/clientraw.txt
RegExp="(?siU).* .* .* .* .* .* .* .* (.*) "
StringIndex=1
[MeasureActualAnnualRain]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url=http://www.sheffieldweather.co.uk/meso2/clientraw.txt
RegExp="(?siU).* .* .* .* .* .* .* .* .* (.*) "
StringIndex=1
[MeasureWindchillTemp]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url=http://www.sheffieldweather.co.uk/meso2/clientraw.txt
RegExp="(?siU).* .* .* .* .* .* .* .* .* .* .* .* .* .* .* .* .* .*.* .* .* .* .* .* .* .* .*.* .*
.* .* .* .* .* .* .*.* .* .* .* .* .* .* .* .* (.*) "
StringIndex=1
;----------------METERS--------------------
[MeterTempText]
Meter=String
MeasureName=MeasureActualTemp
X=5
Y=5
W=150
H=300
FontColor=#Colour2#
Text="Temperature: %1°C"
AntiAlias=1
[MeterWindchillText]
Meter=String
MeasureName=MeasureWindchillTemp
X=5
Y=15r
FontColor=#Colour2#
Text="Windchill: %1°C"
AntiAlias=1
[MeterHumidityText]
Meter=String
MeasureName=MeasureActualHumidity
X=5
Y=15r
FontColor=#Colour2#
Text="Humidity: %1%"
AntiAlias=1
[MeterPressureText]
Meter=String
MeasureName=MeasureActualPressure
X=5
Y=15r
FontColor=#Colour2#
Text="Pressure: %1mB"
AntiAlias=1
[MeterDailyRainText]
Meter=String
MeasureName=MeasureActualDailyRain
X=5
Y=15r
FontColor=#Colour2#
Text="Daily rain: %1mm"
AntiAlias=1
[MeterMonthlyRainText]
Meter=String
MeasureName=MeasureActualMonthlyRain
X=5
Y=15r
FontColor=#Colour2#
Text="Monthly rain: %1mm"
AntiAlias=1
[MeterAnnualRainText]
Meter=String
MeasureName=MeasureActualAnnualRain
X=5
Y=15r
FontColor=#Colour2#
Text="Annual rain: %1mm"
AntiAlias=1
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Help needed with RegExps counting whitespaces...
Add Debug=2 to your WebParser measure. Then refresh. You should have a file called WebParserDump.txt in the root directory of your C: drive.
What's in it?
What's in it?