LittleOne wrote: ↑February 7th, 2020, 9:46 am[...]what i need is to get the value after
"summary": " since its not always "Test"
maybe its simpler to say that it is calendar event and its always changed i need to get the
summary value for every single
Date Value its not always have 3 event only it can be just one or whatever number exist, the length of summary value is not always same
As promised, I came back with a solution, after getting home.
Now I'm assuming you have no spaces, tab or new line characters (i.e.
\s*) in your string, as what you presented might have been formatted this way for clarity. In this case, for the unspaced string:
Code: Select all
{"items":[{"summary":"Test 1","start":{"date":"2020-02-09"}},{"summary":"Test 2","start":{"date":"2020-02-11"}},{"summary":"Test 3","start":{"date":"2020-02-17"}}]}
, this regex will do the trick, by capturing the desired summary and date in
\1 and
\2:
Code: Select all
(?siU)\{"items":\[\{(?:.*\}(?:,\{|\])){0,1}+"summary":"(.*)","start":\{"date":"(.*)"\}.*\}(?:,\{|\])
In case you do have spaces, tab or new line characters in your string, just use
\s* where needed:
Code: Select all
(?siU)\{\s*"items":\s*\[\s*\{(?:.*\}(?:,\s*\{|\s*\])){0,1}+\s*"summary":\s*"(.*)",\s*"start":\s*\{\s*"date":\s*"(.*)"\s*\}.*\}(?:,\s*\{|\s*\])
The above regex works by counting the predecessors of the item where you actually capture, so if you need data from the 1st item you have
{0,0}+ in the regex, if you need the 2nd you have
{0,1}+, if you need the 3rd you have
{0,2}+ and so on. Basically you only have to modify a single number to "jump" to a different item. If you want, you can store that number in a variable in Rainmeter, and assuming you work with string (the WebParser case is more problematic since a dynamic
StringIndex option requires updating the parent measure) measures and have
DynamicVariables=1 in the right places, you'll be able to control which item you need data from.
As I said, you should be careful with the problem of balancing arbitrary paranthesis, choosing your anchors (the boundaries of your patterns) wisely. Since there's no solution for that other than regex recursion, and recursion is not compatible with Rainmeter as far as I tested, you are out of luck if you don't know where the most relevant parathesis occur in your string.
P.S. The above was tested in regexr.com, and this method of getting the n-th item in a "list" has been extensively used in my skins for years, so it's reliable.