Page 1 of 1
Rainmeter Regular expression behaving differently to expected
Posted: January 11th, 2018, 5:07 pm
by DigitalEssence
Hi,
I have a reg ex that doesn't work as I expect it to in Rainmeter but does in 2 online reg ex tools.
The string is:
Code: Select all
<observation_time_rfc822>Thu, 11 Jan 2018 16:30:01 +0000</observation_time_rfc822>
and the regex is to pull out the time from this string in the format of xx:xx:xx
Code: Select all
(?siU)<observation_time_rfc822>.*?(\d{1,2}:\d{1,2}:\d{1,2}).*?</observation_time_rfc822>
In Rainmeter and the Fabulous RainRegExp tool it is giving me:
But in this online tool:
https://regex101.com/r/gMHSt4/4 it works as I expect (I may well be wrong as I usually am)
It also works as I expect here:
https://regexr.com/3j3f7 and outputs:
I have a workaround and that is to change the {1,2} to {2} which is probably a better option as the time format will, I assume always have two digits but should {1,2} not match correctly in Rainmeter?
thanks,
Hedley
Re: Rainmeter Regular expression behaving differently to expected
Posted: January 11th, 2018, 5:17 pm
by SilverAzide
When I try your example on regex101.com it agrees with Rainmeter, not your other sites.
I think the key is this: {1,2} Quantifier — Matches between 1 and 2 times,
as few times as possible, expanding as needed (lazy)
So since 1 digit matched, that's what it returned...
Also, using ".*?" (greedy) instead of ".*" (lazy) changes things too.
Re: Rainmeter Regular expression behaving differently to expected
Posted: January 11th, 2018, 5:27 pm
by DigitalEssence
SilverAzide wrote:When I try your example on regex101.com it agrees with Rainmeter, not your other sites.
I think the key is this: {1,2} Quantifier — Matches between 1 and 2 times,
as few times as possible, expanding as needed (lazy)
So since 1 digit matched, that's what it returned...
Hi SilverAzide,
thanks for your reply.
I see what you mean if I set it to lazy then it matches with Rainmeter.
Re: Rainmeter Regular expression behaving differently to expected
Posted: January 11th, 2018, 5:42 pm
by FreeRaider
DigitalEssence wrote:Hi,
I have a reg ex that doesn't work as I expect it to in Rainmeter but does in 2 online reg ex tools.
The string is:
Code: Select all
<observation_time_rfc822>Thu, 11 Jan 2018 16:30:01 +0000</observation_time_rfc822>
and the regex is to pull out the time from this string in the format of xx:xx:xx
Code: Select all
(?siU)<observation_time_rfc822>.*?(\d{1,2}:\d{1,2}:\d{1,2}).*?</observation_time_rfc822>
In Rainmeter and the Fabulous RainRegExp tool it is giving me:
But in this online tool:
https://regex101.com/r/gMHSt4/4 it works as I expect (I may well be wrong as I usually am)
It also works as I expect here:
https://regexr.com/3j3f7 and outputs:
I have a workaround and that is to change the {1,2} to {2} which is probably a better option as the time format will, I assume always have two digits but should {1,2} not match correctly in Rainmeter?
thanks,
Hedley
apart from that you use /g (that is the global flag in
https://regex101.com/r/gMHSt4/4 and in rainmeter it does not work) ... but simply put \s+ after ")"
(?siU)<observation_time_rfc822>.*?(\d{1,2}:\d{1,2}:\d{1,2})[color=#FF0000]\s+[/color].*?</observation_time_rfc822>
Re: Rainmeter Regular expression behaving differently to expected
Posted: January 11th, 2018, 6:25 pm
by balala
DigitalEssence wrote:The string is:
Code: Select all
<observation_time_rfc822>Thu, 11 Jan 2018 16:30:01 +0000</observation_time_rfc822>
and the regex is to pull out the time from this string in the format of xx:xx:xx
Code: Select all
(?siU)<observation_time_rfc822>.*?(\d{1,2}:\d{1,2}:\d{1,2}).*?</observation_time_rfc822>
I also would like to add three things, beside what SilverAzide and FreeRaider said:
- Why have you put those question marks there? First I'd remove them ((?siU)<observation_time_rfc822>.*[color=#FF0000]?[/color](\d{1,2}:\d{1,2}:\d{1,2}).*[color=#FF0000]?[/color]</observation_time_rfc822>).
- The second step would be to add a space both before and after the matching string (this is practically the same solution as FreeRaider's one).
- And a last recommendation would be to avoid the need os having after the observation_time string, the rfc822 string. Not knowing your source and how does it behaves, I'm not sure, but would say there the string can change. That's why I'd use there a .*.
All these being said, here is my propose on the RegExp:
RegExp=(?siU)<observation_time.*>.* (\d{1,2}:\d{1,2}:\d{1,2}) .*</observation_time.*>.
See the space between the
<observation_time.*>.* and the matched numbers, respectively between those numbers and the final
.*</observation_time.*>. Using FreeRaider's solution, this would be:
RegExp=(?siU)<observation_time.*>.*\s+(\d{1,2}:\d{1,2}:\d{1,2})\s+.*</observation_time.*>.
Re: Rainmeter Regular expression behaving differently to expected
Posted: January 12th, 2018, 5:25 pm
by DigitalEssence
balala wrote:I also would like to add three things, beside what SilverAzide and FreeRaider said:
- Why have you put those question marks there? First I'd remove them ((?siU)<observation_time_rfc822>.*[color=#FF0000]?[/color](\d{1,2}:\d{1,2}:\d{1,2}).*[color=#FF0000]?[/color]</observation_time_rfc822>).
- The second step would be to add a space both before and after the matching string (this is practically the same solution as FreeRaider's one).
- And a last recommendation would be to avoid the need os having after the observation_time string, the rfc822 string. Not knowing your source and how does it behaves, I'm not sure, but would say there the string can change. That's why I'd use there a .*.
All these being said, here is my propose on the RegExp:
RegExp=(?siU)<observation_time.*>.* (\d{1,2}:\d{1,2}:\d{1,2}) .*</observation_time.*>.
See the space between the
<observation_time.*>.* and the matched numbers, respectively between those numbers and the final
.*</observation_time.*>. Using FreeRaider's solution, this would be:
RegExp=(?siU)<observation_time.*>.*\s+(\d{1,2}:\d{1,2}:\d{1,2})\s+.*</observation_time.*>.
Hi,
the question mark is there as it makes it not-greedy.
Or does in Perl. As far as I know...
The source xml has the following options for the time:
Code: Select all
<observation_time>Last Updated on January 12, 4:49 PM GMT</observation_time>
<observation_time_rfc822>Fri, 12 Jan 2018 16:49:59 +0000</observation_time_rfc822>
<observation_epoch>1515775799</observation_epoch>
<local_time_rfc822>Fri, 12 Jan 2018 16:53:01 +0000</local_time_rfc822>
<local_epoch>1515775981</local_epoch>
Whether this may change or not I don't know.
Thanks for your updates. I will run through them and update my skin.
Thanks as always.
Re: Rainmeter Regular expression behaving differently to expected
Posted: January 12th, 2018, 7:10 pm
by balala
Ok, let us know if the posted solutions did work.
Re: Rainmeter Regular expression behaving differently to expected
Posted: January 12th, 2018, 9:24 pm
by SilverAzide
DigitalEssence wrote:Whether this may change or not I don't know.
It will not, which is nice. The reference in the tag to "rfc822" means that this is a timestamp formatted per
RFC-822. You can safely parse this without worrying about a format change.
Re: Rainmeter Regular expression behaving differently to expected
Posted: January 13th, 2018, 10:21 am
by DigitalEssence
balala wrote:Ok, let us know if the posted solutions did work.
Yes, the solution posted works:
Code: Select all
.*\s+(\d{1,2}:\d{1,2}:\d{1,2})\s+.*
And I was hoping that because it was formatted to rfc822 that I was safe but in the short period I have been active on this forum, I'm learning not to assume anything
Thanks for your help. Resolved.
Re: Rainmeter Regular expression behaving differently to expected
Posted: January 13th, 2018, 7:20 pm
by balala
Glad to help.