balala wrote: ↑November 20th, 2018, 10:27 am
Yes, but the question still remains: why in the original code (posted by austrini in the initial post of this topic) the [MeasureReviews] measure returns the whole
reviews_available":19, string, not just the number? Because in the RegExp option of the [MeasureReviews] measure
(.*) would mean just 19, not the whole
reviews_available":19,.
Code: Select all
[MeasureSite]
Measure=Webparser
URL=https://bunpro.jp/api/user/#APIKey#/study_queue
RegExp=(?siU)^(.*)$
[MeasureReviews]
Measure=Webparser
URL=[MeasureSite]
RegExp=(?siU)reviews_available":(.*),
If we leave WebParser out of this for a second, regular expression in and of itself is simply about "matching". A (capture group) doesn't cause the match to be any less or more than what is defined in the regular expression.
So in purely regular expression terms if we have the string:
{"reviews_available":19,"next_review_date":1541692800,"reviews_available_next_hour":19,"reviews_available_next_day":19}}
Then
(?siU)^(.*)$ matches the entire string.
And
(?siU)reviews_available":(.*), matches
reviews_available":19,, and creates a (capture group) consisting of
19 with an index of 1.
With WebParser, it is the StringIndex on the child measure that returns the value of the indexed (capture group), or
19. Without a StringIndex, the entire match is returned.
That is the difference between a "parent" and "child" WebParser measure. A parent measure always returns the entire match, and creates (capture groups), indexed in the order they are in the regular expression. A child measure uses StringIndex to extract one of the indexed (capture groups) values from the parent, and returns just that. A WebParser measure cannot be a child without StringIndex.
Now as I said, a WebParser measure can be BOTH a "parent' and a "child" measure.
Code: Select all
[MeasureSite]
Measure=WebParser
URL=https://bunpro.jp/api/user/#APIKey#/study_queue
RegExp=(?siU)reviews_available":(.*),
StringIndex=1
It is the RegExp that defines the "match", which will be
reviews_available":19,, and the StringIndex that extracts the single (capture group) that has a value of
19. Think of
RegExp as the "parent" bit, and
StringIndex as the "child" bit.