It is currently March 29th, 2024, 12:16 pm

Regex outside of Webparser

Get help with creating, editing & fixing problems with skins
sundansx
Posts: 4
Joined: February 8th, 2014, 10:31 pm

Regex outside of Webparser

Post by sundansx »

I am making a skin that calls a python class and returns this text:

Code: Select all

Minutes : 1000,Text Msg: 2000,Data(MB): 3000,End Date: 07/03/2019
I want to use this regex to pull data out of it:

Code: Select all

(?siU)Minutes : ([0-9]+).*,Text Msg: ([0-9]+),Data\(MB\): ([0-9]+),End Date: ([0-9]+/[0-9]+/[0-9]+)
The RainRegExp tool shows these capture groups:

Code: Select all

1 => 1
2 => 2000
3 => 3000
4 => 07/03/2
Can I use the webparser like this? It's not working as is, is there a better way? Thanks.

Code: Select all

[measureInfo]
Measure=Plugin
Plugin=Python
PythonHome=E:\Programming\python33
ScriptPath=pyTrac.py
ClassName=TracStatus
phoneNum=#phoneNumVar#
UpdateDivider=1

[MeasureChild1]
Measure=WebParser
URL=[measureInfo]
RegExp=(?siU)Minutes : ([0-9]+).*,Text Msg: ([0-9]+),Data\(MB\): ([0-9]+),End Date: ([0-9]+/[0-9]+/[0-9]+)

[MeasureChild2]
Measure=WebParser
URL=[MeasureChild1]
StringIndex=1

[meterBalances]
Meter=STRING
MeterStyle=styleLeftText
MeasureName=MeasureChild2
X=10
Y=40
W=190
H=14
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Regex outside of Webparser

Post by ikarus1969 »

In this case you can delete the U in (?siU). The U means "ungreedy" and catches only the minimum of characters of a class.
So at the beginning a "(?siU)Minutes : ([0-9]+).*,..." captures only the first digit of "Minutes : 1000,..."

so you can use (without the U):

Code: Select all

(?si)Minutes : ([0-9]+).*,Text Msg: ([0-9]+),Data\(MB\): ([0-9]+),End Date: ([0-9]+/[0-9]+/[0-9]+)
or, another possibility (for this specific case) would be:

Code: Select all

(?siU)Minutes : ([^,]+),Text Msg: ([0-9]+),Data\(MB\): ([0-9]+),End Date: ([0-9]+/[0-9]+/[0-9]+$)
the [^,]+ at the beginning means: capture everything but a ,
the [0-9]+$ at the end means: capture all digits at the end of the string ($ means "the end of the string")
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Regex outside of Webparser

Post by balala »

Beside ikarus1969's reply, I'd note another thing too. Although I'm not using the Python plugin and I don't know how it does work, I suppose that your code doesn't work because then [MeasureChild1] WebParser measure should have to be updated when the [measureInfo] measure gets its value. There are two possibilities:
  • If the Python plugin measure does support a FinishAction option, it's much easier. Just have to add a FinishAction=[!CommandMeasure "MeasureChild1" "Update"] option to the [measureInfo] measure. However I think this solution doesn't work, because it seems the Python plugin measures don't support the FinishAction option.
  • If it indeed doesn't support the FinishAction option, there is needed another approach. Try to add to the same [measureInfo] measure, the following option: OnChangeAction=[!CommandMeasure "MeasureChild1" "Update"].
Again, since I'm not using the plugin, I'm not sure if any of these solutions will work, but maybe it worth a try.