It is currently February 29th, 2020, 4:15 am

Regexp again (i hope you not bored with this question)

Help with creating, editing & fixing problems with skins
User avatar
LittleOne
Posts: 48
Joined: March 24th, 2015, 4:03 am

Re: Regexp again (i hope you not bored with this question)

Post by LittleOne »

No you done nothing wrong, its understandable reaction after see that much of code and no i not that lazy to ask someone modifying my skin code

yes the _GCal is in debug=2 mode and other webparser is activated when it finish

for example at line 381 there is this

Code: Select all

[_D12]
Measure=Webparser
URL=file://#CURRENTPATH#WebParserDump.txt
DynamicVariables=1
RegExp=(?siU)"date": "[_Year]-[_Month]-12"
OnRegExpErrorAction=[!SetOption M12_ ImageAlpha #DotAlpha#][!DisableMeasure "_D12"]
FinishAction=[!SetOption M12_ ImageAlpha #DotOpaque#][!DisableMeasure "_D12"]
Disabled=1
Group=Date_
as you can see the RegExp here is looking for only specific date "12" the regexp you show is working well if there is a some amount of event, imagine if there is only 1 event, the regexp will hit nothing

Code: Select all

{
 "items": [
  {
   "summary": "Test 1",
   "start": {
    "date": "2020-02-12"
   }
  }
 ]
}
assume this parsed info
with that in mind i need the regexp that anchored at "2020-02-12" and then somehow it look for "summary" backward from that point, is it possible?
Yincognito
Posts: 837
Joined: February 27th, 2015, 2:38 pm

Re: Regexp again (i hope you not bored with this question)

Post by Yincognito »

LittleOne wrote:
February 7th, 2020, 2:37 pm
[...] the regexp you show is working well if there is a some amount of event, imagine if there is only 1 event, the regexp will hit nothing

Code: Select all

{
 "items": [
  {
   "summary": "Test 1",
   "start": {
    "date": "2020-02-12"
   }
  }
 ]
}
assume this parsed info
with that in mind i need the regexp that anchored at "2020-02-12" and then somehow it look for "summary" backward from that point, is it possible?
You are wrong, my regex is hitting exactly what it is supposed to hit - I told you, it is tried and tested over many years (since, like you, I had the same problem back then). It didn't hit anything for you because you expected it to work with {0,1}+ part included. You have to modify that to {0,0}+ instead and it will work.

Basically, if you need data from item N (where N is a positive integer number), you'd have to set the above to {0,N-1}+. The explanation is simple: there are 0 items before item number 1, 1 item before item number 2, 2 items before item number 3, and so on.

 ITEM 1, ITEM 2, ITEM 3, ITEM 4, ITEM 5, ITEM 6, ITEM 7, ....
|                                             |     |
 --------------------------------------      |
                       |                             |
                       v                             v
  (N-1) PREDECESSOR ITEMS   CAPTURED ITEM [N-th]

The above schematic is for N=5, obviously. But it's the same even if there's a single item. And yes, I just tested (again, LOL) my regex against your provided info in the quote and it gave the expected results. I can save the regex on regexr.com and provide a link if you don't believe it. :lol:
User avatar
LittleOne
Posts: 48
Joined: March 24th, 2015, 4:03 am

Re: Regexp again (i hope you not bored with this question)

Post by LittleOne »

sorry, its hard to explain it correctly
assume:

we work at measure [_D12] which is getting event for date "12" only

at this month (feb) there is only one event that is at "2020-02-12" regexp {0,0}+ will capture it correctly

but then the next month (mar) coming and accidentally there is an event too at same date "2020-03-12" but before this date there is an event just say at "2020-03-09" now with this in mind if i not change regexp manually on [_D12] to {0,1}+ it will capture the summary at "9", correct?

so what i need is Regexp that will work for date "12" only in measure [_D12] because the number of event is changing dynamically for every month

once again sorry if i make nerve wracking post, i don't meant to do so.
Yincognito
Posts: 837
Joined: February 27th, 2015, 2:38 pm

Re: Regexp again (i hope you not bored with this question)

Post by Yincognito »

LittleOne wrote:
February 7th, 2020, 4:24 pm
sorry, its hard to explain it correctly
assume:

we work at measure [_D12] which is getting event for date "12" only

at this month (feb) there is only one event that is at "2020-02-12" regexp {0,0}+ will capture it correctly

but then the next month (mar) coming and accidentally there is an event too at same date "2020-03-12" but before this date there is an event just say at "2020-03-09" now with this in mind if i not change regexp manually on [_D12] to {0,1}+ it will capture the summary at "9", correct?

so what i need is Regexp that will work for date "12" only in measure [_D12] because the number of event is changing dynamically for every month

once again sorry if i make nerve wracking post, i don't meant to do so.
I've been busy with other jobs - sorry for the delay. I begin to see what you mean - don't worry about my nerves, they're fine, and I'm not bored either, LOL. You probably stated the problem in the wrong way at the beginning, because I understood that you wanted the N-th "event" (if "events" are the actual items in the source), which my regex does. To answer your question, for a source like you described (if I understood it correctly):

Code: Select all

{
 "items": [
  {
   "summary": "Test 1",
   "start": {
    "date": "2020-02-12"
   }
  },
  {
   "summary": "Test 2",
   "start": {
    "date": "2020-03-09"
   }
  },
  {
   "summary": "Test 3",
   "start": {
    "date": "2020-03-12"
   }
  },
  {
   "summary": "Test 4",
   "start": {
    "date": "2020-03-12"
   }
  },
  {
   "summary": "Test 5",
   "start": {
    "date": "2020-03-15"
   }
  }
 ]
}
you want the 1st, the 3rd and the additional - for testing purposes - 4th event, aka the ones that occur on day 12 of each month (i.e. "Test 1", "Test 3" and "Test 4"), but my regex with {0,1}+ will indeed capture the 2nd event/item, that is "Test 2". What you want is possible, but only if you use substitute in a String measure (i.e. it's not possible for a regex to capture discontinuous/disjoint parts of a text in a single parse / capture as far as I know, and to capture them in separate parses it would have to remember the previous captures, which is again probably not doable).

I think the code below can be satisfactory, and that's pretty much all I can do about it. You should copy paste the source data above to your WebParserDump.txt file, like before, so you can see the result. What it does is:
- first, get everything from the source into the WebParser parent (i.e. [MeasureAnalogCalendar])
- the WebParser parent will trigger a "paste" of the data to [MeasureContents] through its FinishAction, in order to manipulate and extract every event occuring on day 12 of each month
- next, MeasureTarget will get [MeasureContents]'s data and further "chop" it to get the N-th event occuring on day 12 from all the events in [MeasureContents]. This means that if you want to "select" events on day 12 of a specific month, you'd have to do it in the Substitute option of MeasureContents, not here. Here you only "extract" the N-th event from those already existing in [MeasureContents]
- finally, [MeasureSummary] and MeasureDate will extract the summary and the date from the (single or no) event that exists in MeasureTarget. Because of the Substitute in the previous measure, if there's no event to get data from, both the summary and the date will display "None"

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=0,0,0,255

---Measures---

[MeasureAnalogCalendar]
Measure=WebParser
URL=file://#CURRENTPATH#WebParserDump.txt
RegExp="(?siU)^(.*?)$"
FinishAction=[!SetOption MeasureContents String "[MeasureAnalogCalendar]"][!UpdateMeasure "MeasureContents"][!UpdateMeasure "MeasureTarget"][!UpdateMeasure "MeasureSummary"][!UpdateMeasure "MeasureDate"]
DynamicVariables=1

[MeasureContents]
Measure=String
String=
UpdateDivider=-1
RegExpSubstitute=1
Substitute='(?siU)(?:\s*\{\s*"items":\s*|\s*\{\s*"summary"[^\}]*"\d{4}-\d{2}-\d{2}(?<!12)"\s*\}\s*\},*?\s*|(?<=\])\s*\})':""
DynamicVariables=1

[MeasureTarget]
Measure=String
String=[MeasureContents]
UpdateDivider=-1
RegExpSubstitute=1
Substitute='(?siU)^\s*\[\s*\{(?:.*\}(?:,\s*\{|,\s*\])){0,0}+(.*?)$':"\1","(?:^\\1|\\1$)":"None","(?siU)\},\s*\{.*?$":""
DynamicVariables=1

[MeasureSummary]
Measure=String
String=[MeasureTarget]
UpdateDivider=-1
RegExpSubstitute=1
Substitute='(?siU)^\s*?"summary":\s*"(.*)",\s*"start":\s*\{\s*"date":\s*"(.*)"\s*\}.*?$':"\1"
DynamicVariables=1

[MeasureDate]
Measure=String
String=[MeasureTarget]
UpdateDivider=-1
RegExpSubstitute=1
Substitute='(?siU)^\s*?"summary":\s*"(.*)",\s*"start":\s*\{\s*"date":\s*"(.*)"\s*\}.*?$':"\2"
DynamicVariables=1

---Meters---

[MeterSummary]
Meter=String
X=5
Y=5R
MeasureName=MeasureSummary
FontSize=14
FontColor=222,255,227,255
StringStyle=Bold
AntiAlias=1

[MeterDate]
Meter=String
MeasureName=MeasureDate
X=5
Y=5R
FontSize=14
FontColor=222,255,227,255
StringStyle=Bold
AntiAlias=1
Bottom line, MeasureAnalogCalendar will have everything from the source, MeasureContents will have all events occuring on day 12 from the source (but as I said, you can get just those from, say, March, if you edit its Substitute), MeasureTarget will have the N-th such event and MeasureSummary and MeasureDate will have the summary and the date of the N-th event, respectively.

Note: Bear in mind that the "selection" of data in these measures is not done by actual parsing, but by chopping/cutting the rest of the data (the one that's not needed) from the string. So, the "\d{4}-\d{2}-\d{2}(?<!12)" in [MeasureContents] means that every event occuring on a day other than 12 will be eliminated from the string, using the (?<!12) negative lookbehind. If you need to extract, for example, every event occuring on day 12 of March, you'd have to replace (?<!12) with (?<!03-12), and so on.
User avatar
LittleOne
Posts: 48
Joined: March 24th, 2015, 4:03 am

Re: Regexp again (i hope you not bored with this question)

Post by LittleOne »

Finally i can explain the problem ( ノO ωO)ノ -(yay)
Too bad there is no way to capture discontinuous/disjoint parts in 1 parse

That's chopping with substitute is actually works, never thought to done it this way, i think i will approach it with this method, but that's gonna be lot of amount of line to add (⇀‸↼‶i) and hoping that's i not miss a single sequence for every date.

I will mark this problem as solved,
Thanks for the Help and for the patience
(っ∩_∩)っ
Yincognito
Posts: 837
Joined: February 27th, 2015, 2:38 pm

Re: Regexp again (i hope you not bored with this question)

Post by Yincognito »

LittleOne wrote:
February 8th, 2020, 2:06 am
Finally i can explain the problem ( ノO ωO)ノ -(yay)
Too bad there is no way to capture discontinuous/disjoint parts in 1 parse

That's chopping with substitute is actually works, never thought to done it this way, i think i will approach it with this method, but that's gonna be lot of amount of line to add (⇀‸↼‶i) and hoping that's i not miss a single sequence for every date.

I will mark this problem as solved,
Thanks for the Help and for the patience
(っ∩_∩)っ
No problem - glad to help (and also that it solved your problem). ;-)
User avatar
LittleOne
Posts: 48
Joined: March 24th, 2015, 4:03 am

Re: Regexp again (i hope you not bored with this question)

Post by LittleOne »

After tinkering at https://regex101.com/ and read about how to regex from https://www.regular-expressions.info/ and get some info from https://www.cheatography.com/, i found regexp i need for this problem

Code: Select all

{
 "items": [
  {
   "summary": "Other Event 1",
   "start": {
    "date": "2020-02-10"
   }
  },
  {
   "start": {
    "date": "2020-02-12"
   }
  },
  {
   "start": {
    "date": "2020-02-12"
   }
  },
  {
   "summary": "Yes its a test",
   "start": {
    "date": "2020-02-20"
   }
  }
 ]
}
(?iU)(?(?=.*"summary":)"summary": "(.*)",\n.*\n.*)"date": "2020-02-20"
removing s from pattern modifier and put the summary in if clause this regexp able to capture the summary if it exist and by moving the "date": "2020-02-20" outside of the if clause, rainmeter webparser can avoid regexp error if there is an event without summary which is triggering the marker on that certain date and triggering rainmeter regex error if that date has no event (it needed for making mark disappear on that date with OnRegExpErrorAction)
Last edited by LittleOne on February 9th, 2020, 1:34 pm, edited 1 time in total.
Yincognito
Posts: 837
Joined: February 27th, 2015, 2:38 pm

Re: Regexp again (i hope you not bored with this question)

Post by Yincognito »

LittleOne wrote:
February 9th, 2020, 6:55 am
After tinkering at https://regex101.com/ and read about how to regex from https://www.regular-expressions.info/ and get some info from https://www.cheatography.com/, i found regexp i need for this problem
The problem with the regex sites and Rainmeter is that it's not always a regex tested online will work as expected in Rainmeter or RainRegExp. This does it job online, but fails to produce the right results in Rainmeter. Anyway, if it works for you, that's fantastic.