It is currently March 29th, 2024, 8:45 am

pls help(regexp)

General topics related to Rainmeter.
User avatar
goeway
Posts: 21
Joined: March 20th, 2019, 8:50 pm

pls help(regexp)

Post by goeway »

Code: Select all

DefaultJson=["2019-02-28,2,3%,1,1%,1,2%,2,0%,2,3%,2,0%,9,0%","2019-03-01,-1,-1%,7,0%,-1,-2%,2,0%,1,2%,2,1%,9,1%",......,"2019-07-24,4,1%,6,1%,-1,0%,-5,-1%,5,0%,2,0%,9,0%"];

A total of 100 days of data, but not sure if it will change, in this case, how to use regexp to get the data of 2019-07-24, which is the data of the last date (translate by google)
Last edited by goeway on February 11th, 2023, 11:23 am, edited 4 times in total.
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: pls help(regexp)

Post by ikarus1969 »

goeway wrote: July 25th, 2019, 4:52 am

Code: Select all

DefaultJson=["2019-02-28,2,3%,1,1%,1,2%,2,0%,2,3%,2,0%,9,0%","2019-03-01,-1,-1%,7,0%,-1,-2%,2,0%,1,2%,2,1%,9,1%",......,"2019-07-24,4,1%,6,1%,-1,0%,-5,-1%,5,0%,2,0%,9,0%"];
一共100天的数据,但是不确定它会不会有所变动,在这种情况下,如何使用regexp获得2019-07-24的各项数据,也就是最后那个日期的数据。

A total of 100 days of data, but not sure if it will change, in this case, how to use regexp to get the data of 2019-07-24, which is the data of the last date (translate by google)
the regular-expression would be:

Code: Select all

(?siU)"([^"]+)"\]
what you would get with this regular-expression with your example is the following string:
2019-07-24,4,1%,6,1%,-1,0%,-5,-1%,5,0%,2,0%,9,0%


if you want the parts of this string (i assume: there are always the same fixed number of parts, all parts have the same look as in your example) you can use the following regular expression:

Code: Select all

(?siU)"([^,]+),([^%]+%),([^%]+%),([^%]+%),([^,]+),([^%]+%),([^%]+%),([^%]+%),([^%]+%)"\]
what you get with this by using a String-Index value from 1 to 9:

String-Index 1: 2019-07-24
String-Index 2: 4,1%
String-Index 3: 6,1%
String-Index 4: -1,0%
String-Index 5: -5
String-Index 6: -1%
String-Index 7: 5,0%
String-Index 8: 2,0%
String-Index 9: 9,0%
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: pls help(regexp)

Post by balala »

goeway wrote: July 25th, 2019, 4:52 am A total of 100 days of data, but not sure if it will change, in this case, how to use regexp to get the data of 2019-07-24, which is the data of the last date (translate by google)
I'm not sure I completely understood, but at least if I did, here is a (possible) solution.
So, I suppose you have a site, where those information are shown. All of them have the same structure, but the dates (and probably the strings as well) are different (supposably in order) and you'd like to get the last date. Am I right?
If I am, you'd need to use a Lookahead Assertion, especially if you don't know how many dates are there. This will ensure you the parent WebParser measure ([MeasureRainmeter]) doesn't fail when no enough dates are on the site.
For each existing date, a variable is set to 1 (Date1 - Date10 - Just up to 10 dates for now, see below). Finally based on the number of the variables set to 1, a measure ([MeasureDates]) returns the last date in the list.
The following code works for now only with up to 10 dates. If needed, the code can be rewritten, adding further sections, to check even more information. But first please take a look to it and tell me if I indeed have correctly understood your need. To get this code to work, add the appropriate URL of the site you're working with to the URL option of the [MeasureRainmeter] measure.

Code: Select all

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

[Variables]
Item=(?(?=.*regexp).*(\d{4}-\d{2}-\d{2}).*)
Date1=0
Date2=0
Date3=0
Date4=0
Date5=0
Date6=0
Date7=0
Date8=0
Date9=0
Date10=0

[MeasureRainmeter]
Measure=WebParser
UpdateRate=10
Url=- ADD HERE THE URL -
RegExp=(?siU)#Item##Item##Item##Item##Item##Item##Item##Item##Item##Item#
FinishAction=[!EnableMeasureGroup "Child"][!UpdateMeasureGroup "Child"]

[MeasureDate1]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=1
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date1 "1"]
IfNotMatchAction=[!SetVariable Date1 "0"]
Group=Child
Disabled=1

[MeasureDate2]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=2
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date2 "1"]
IfNotMatchAction=[!SetVariable Date2 "0"]
Group=Child
Disabled=1

[MeasureDate3]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=3
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date3 "1"]
IfNotMatchAction=[!SetVariable Date3 "0"]
Group=Child
Disabled=1

[MeasureDate4]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=4
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date4 "1"]
IfNotMatchAction=[!SetVariable Date4 "0"]
Group=Child
Disabled=1

[MeasureDate5]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=5
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date5 "1"]
IfNotMatchAction=[!SetVariable Date5 "0"]
Group=Child
Disabled=1

[MeasureDate6]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=6
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date6 "1"]
IfNotMatchAction=[!SetVariable Date6 "0"]
Group=Child
Disabled=1

[MeasureDate7]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=7
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date7 "1"]
IfNotMatchAction=[!SetVariable Date7 "0"]
Group=Child
Disabled=1

[MeasureDate8]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=8
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date8 "1"]
IfNotMatchAction=[!SetVariable Date8 "0"]
Group=Child
Disabled=1

[MeasureDate9]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=9
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date9 "1"]
IfNotMatchAction=[!SetVariable Date9 "0"]
Group=Child
Disabled=1

[MeasureDate10]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=10
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date10 "1"]
IfNotMatchAction=[!SetVariable Date10 "0"]
Group=Child
Disabled=1

[MeasureDates]
Measure=Calc
Formula=( #Date1# + #Date2# + #Date3# + #Date4# + #Date5# + #Date6# + #Date7# + #Date8# + #Date9# + #Date10# )
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(\d{1,3})$":"[&MeasureDate[&#CURRENTSECTION#]]"
Group=Child
Disabled=1

[MeterLastDate]
Meter=STRING
MeasureName=MeasureDates
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=Last date:#CRLF#%1
User avatar
goeway
Posts: 21
Joined: March 20th, 2019, 8:50 pm

Re:pls help(regexp)

Post by goeway »

ikarus1969 wrote: July 25th, 2019, 5:57 am the regular-expression would be:

Code: Select all

(?siU)"([^"]+)"\]
what you would get with this regular-expression with your example is the following string:
2019-07-24,4,1%,6,1%,-1,0%,-5,-1%,5,0%,2,0%,9,0%


if you want the parts of this string (i assume: there are always the same fixed number of parts, all parts have the same look as in your example) you can use the following regular expression:

Code: Select all

(?siU)"([^,]+),([^%]+%),([^%]+%),([^%]+%),([^,]+),([^%]+%),([^%]+%),([^%]+%),([^%]+%)"\]
what you get with this by using a String-Index value from 1 to 9:

String-Index 1: 2019-07-24
String-Index 2: 4,1%
String-Index 3: 6,1%
String-Index 4: -1,0%
String-Index 5: -5
String-Index 6: -1%
String-Index 7: 5,0%
String-Index 8: 2,0%
String-Index 9: 9,0%
:thumbup: :rosegift: :rosegift:
Thank you, ikarus1969, your reply helped me solve the problem. I changed it a bit, so that it can get the last date and every item after it.
RegExp=(?siU)"([^,]+),([^,]+),([^%]+%),([^,]+),([^%]+%),([^,]+),([^%]+%),([^,]+),([^%]+%),([^,]+),([^%]+%),([^,]+),([^%]+%),([^,]+),([^%]+%)"\]
Last edited by goeway on February 11th, 2023, 11:23 am, edited 2 times in total.
User avatar
goeway
Posts: 21
Joined: March 20th, 2019, 8:50 pm

Re: 请帮忙(注册)

Post by goeway »

balala wrote: July 25th, 2019, 6:04 am I'm not sure I completely understood, but at least if I did, here is a (possible) solution.
So, I suppose you have a site, where those information are shown. All of them have the same structure, but the dates (and probably the strings as well) are different (supposably in order) and you'd like to get the last date. Am I right?
If I am, you'd need to use a Lookahead Assertion, especially if you don't know how many dates are there. This will ensure you the parent WebParser measure ([MeasureRainmeter]) doesn't fail when no enough dates are on the site.
For each existing date, a variable is set to 1 (Date1 - Date10 - Just up to 10 dates for now, see below). Finally based on the number of the variables set to 1, a measure ([MeasureDates]) returns the last date in the list.
The following code works for now only with up to 10 dates. If needed, the code can be rewritten, adding further sections, to check even more information. But first please take a look to it and tell me if I indeed have correctly understood your need. To get this code to work, add the appropriate URL of the site you're working with to the URL option of the [MeasureRainmeter] measure.

Code: Select all

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

[Variables]
Item=(?(?=.*regexp).*(\d{4}-\d{2}-\d{2}).*)
Date1=0
Date2=0
Date3=0
Date4=0
Date5=0
Date6=0
Date7=0
Date8=0
Date9=0
Date10=0

[MeasureRainmeter]
Measure=WebParser
UpdateRate=10
Url=- ADD HERE THE URL -
RegExp=(?siU)#Item##Item##Item##Item##Item##Item##Item##Item##Item##Item#
FinishAction=[!EnableMeasureGroup "Child"][!UpdateMeasureGroup "Child"]

[MeasureDate1]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=1
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date1 "1"]
IfNotMatchAction=[!SetVariable Date1 "0"]
Group=Child
Disabled=1

[MeasureDate2]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=2
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date2 "1"]
IfNotMatchAction=[!SetVariable Date2 "0"]
Group=Child
Disabled=1

[MeasureDate3]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=3
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date3 "1"]
IfNotMatchAction=[!SetVariable Date3 "0"]
Group=Child
Disabled=1

[MeasureDate4]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=4
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date4 "1"]
IfNotMatchAction=[!SetVariable Date4 "0"]
Group=Child
Disabled=1

[MeasureDate5]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=5
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date5 "1"]
IfNotMatchAction=[!SetVariable Date5 "0"]
Group=Child
Disabled=1

[MeasureDate6]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=6
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date6 "1"]
IfNotMatchAction=[!SetVariable Date6 "0"]
Group=Child
Disabled=1

[MeasureDate7]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=7
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date7 "1"]
IfNotMatchAction=[!SetVariable Date7 "0"]
Group=Child
Disabled=1

[MeasureDate8]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=8
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date8 "1"]
IfNotMatchAction=[!SetVariable Date8 "0"]
Group=Child
Disabled=1

[MeasureDate9]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=9
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date9 "1"]
IfNotMatchAction=[!SetVariable Date9 "0"]
Group=Child
Disabled=1

[MeasureDate10]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=10
IfMatch=\d{4}-\d{2}-\d{2}
IfMatchAction=[!SetVariable Date10 "1"]
IfNotMatchAction=[!SetVariable Date10 "0"]
Group=Child
Disabled=1

[MeasureDates]
Measure=Calc
Formula=( #Date1# + #Date2# + #Date3# + #Date4# + #Date5# + #Date6# + #Date7# + #Date8# + #Date9# + #Date10# )
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(\d{1,3})$":"[&MeasureDate[&#CURRENTSECTION#]]"
Group=Child
Disabled=1

[MeterLastDate]
Meter=STRING
MeasureName=MeasureDates
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=Last date:#CRLF#%1

:rosegift: :rosegift: :rosegift:
Thank you for your reply, I solved the problem with ikarus1969's method, I believe that your method will help me to write in the future.
Last edited by goeway on February 12th, 2021, 7:54 am, edited 1 time in total.
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: pls help(regexp)

Post by ikarus1969 »

goeway wrote: July 25th, 2019, 7:52 am :thumbup: :rosegift: :rosegift:
多谢你,ikarus1969,你的回复帮我解决了问题。我稍为改了一下,使得它能够得到最后的那个日期以及后面的每一项数据。(Thank you, ikarus1969, your reply helped me solve the problem. I changed it a bit, so that it can get the last date and every item after it.)
You're welcome!

Maybe you can post your skin when you have finished it (maybe in the "Share Your Creations"-section of the forum: https://forum.rainmeter.net/viewforum.php?f=27)
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: pls help(regexp)

Post by balala »

goeway wrote: July 25th, 2019, 7:59 am (Thank you for your reply, I solved the problem with ikarus1969's method, I believe that your method will help me to write in the future.)
Ok, as you wish.
User avatar
goeway
Posts: 21
Joined: March 20th, 2019, 8:50 pm

重新:pls help(regexp)

Post by goeway »

ikarus1969 wrote: July 25th, 2019, 8:10 am You're welcome!

Maybe you can post your skin when you have finished it (maybe in the "Share Your Creations"-section of the forum: https://forum.rainmeter.net/viewforum.php?f=27)