It is currently March 29th, 2024, 7:10 am

Do alternate positive lookbehinds work in Rainmeter?

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Do alternate positive lookbehinds work in Rainmeter?

Post by Yincognito »

I have a text like this (part of an attempt to process feeds in my skin):

Code: Select all

<f>
	<l> rel="self" type="application/atom+xml" href="https://forum.rainmeter.net/feed" </l>

	<t>Rainmeter Forums</t>
	
	<l> href="https://forum.rainmeter.net/index.php" </l>
	<u>2019-02-27T22:02:34</u>

	<author><name><![CDATA[Rainmeter Forums]]></name></author>
	<id>https://forum.rainmeter.net/feed</id>

		<e>
		<author><name><![CDATA[dumb hobo]]></name></author>
		<u>2019-02-27T22:02:34</u>

		<p>2019-02-27T22:02:34</p>
		<id>https://forum.rainmeter.net/viewtopic.php?t=27717&p=159674#p159674</id>
		<l> href="https://forum.rainmeter.net/viewtopic.php?t=27717&p=159674#p159674"</l>
		<t><![CDATA[Help: Rainmeter Skins • Re: sliding in and and out a sidebar along with all its components]]></t>

					<category> term="Help: Rainmeter Skins" scheme="https://forum.rainmeter.net/viewforum.php?f=5" label="Help: Rainmeter Skins"</category>
		
		<s><![CDATA[
You can contact me i can give you my info in message just in case !<p>Statistics: Posted by <a href="https://forum.rainmeter.net/memberlist.php?mode=viewprofile&u=48282">dumb hobo</a> — Yesterday, 10:02 pm</p><hr> </hr>
]]></s>
	</e></f>
and a regex like this in a substitute:

"(?siU)(?<=<f>|<e>|</e>|</t>|</s>|</l>|</u>|</p>|</o>).*(?=</f>|</e>|<e>|<t>|<s>|<l>|<u>|<p>|<o>)":""

What I'm looking for is to delete anything (non-greedy) between my custom starting and ending tags above, basically cleaning the text of unneeded parts. Now, if I enter the text and the equivalent of the regex above at RegExR (PCRE flavor selected, same flags being set, etc.), everything works fine and the appropriate selection is made and deleted, but when I apply the regex in Rainmeter, it deletes the whole content, leaving me with <f></f>. Why is that, and how can I correct it? Please don't tell me that positive lookbehinds don't work in Rainmeter, cause I'll be extremely upset by it... :x

NOTE: The / must be escaped at RegExR, so the regex will have to be entered like this:
(?<=<f>|<e>|<\/e>|<\/t>|<\/s>|<\/l>|<\/u>|<\/p>|<\/o>).*(?=<\/f>|<\/e>|<e>|<t>|<s>|<l>|<u>|<p>|<o>)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Do alternate positive lookbehinds work in Rainmeter?

Post by jsmorley »

User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Do alternate positive lookbehinds work in Rainmeter?

Post by Yincognito »

Come on now, this is all you got? I read most of the things in those links already, but it doesn't answer my question: same string, same regex, same flavor ... but different results.

By the way, this also works as it is supposed to in RegexBuddy, for both PCRE 8.36-8.37 UTF-8 and PCRE2 10.10 ...
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Do alternate positive lookbehinds work in Rainmeter?

Post by jsmorley »

Substitute is not the same as RegExp. Substitute is a "global search and replace", is always "ungreedy", and I'm not sure I see the intent of your lookarounds. You are not saying "match this if that is before or after it", which is the point of lookarounds.

As I see it, all you need is:

Code: Select all

[MeasureString]
Measure=String
String=<em>One <i>Two</i></em>
RegExpSubstitute=1
Substitute="<em>|</em>|<i>|</i>":""

1.jpg


(?si) can be of some value if you are want to ignore case and are returning a string in a [MeasureName] that has linefeeds in it. I'd have to test, I'm not even sure the "s" in that has any effect with a global search and replace.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Do alternate positive lookbehinds work in Rainmeter?

Post by jsmorley »

If the intent is to delete everything "between" two tags, you might look at:

Code: Select all

[MeasureString]
Measure=String
String=<em>One <I>Two</i></em> Three Four
RegExpSubstitute=1
Substitute="(?i)<em>.*</em>|<i>.*</i>":""

1.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Do alternate positive lookbehinds work in Rainmeter?

Post by jsmorley »

Or see this:

Code: Select all

[MeasureString]
Measure=String
String=<em>One <i>Two</i></em> Three Four <i>Five</i>
RegExpSubstitute=1
Substitute="<em>.*</em>|<i>.*</i>":""

1.jpg

Note that it is by its nature "ungreedy"...
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Do alternate positive lookbehinds work in Rainmeter?

Post by jsmorley »

Note that this is a "global search and replace", not a "positional search and replace". You can't search for and delete the first instance of <em>.*</em> and not delete the second instance of it. If some sequence of characters is searched for and replaced with "", an empty string, that will be true for the entire string, globally. If that is what you want, then Substitute is not the answer, it's not what it meant for. To do that, you have to do it in the RegExp that captures the data to begin with.

Something like:

Substitute="<em>(.*)</em>.*<em>(.*)</em>":""

is meaningless...
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Do alternate positive lookbehinds work in Rainmeter?

Post by Yincognito »

Appreciate the replies, jsmorley, but I think I found the solution (and the culprit as well). I was using lookarounds to exclude the tags from being included in the match (since if you delete a tag, you can't use it anymore as a reference point to find the next match, right?), but then, a good night sleep to refresh my mind did the trick: I didn't have to use two lookarounds, one was enough. So, the failing:

Code: Select all

"(?siU)(?<=<f>|<e>|</e>|</t>|</s>|</l>|</u>|</p>|</o>).*(?=</f>|</e>|<e>|<t>|<s>|<l>|<u>|<p>|<o>)":""
could be transformed into:

Code: Select all

"(?siU)(<f>|<e>|</e>|</t>|</s>|</l>|</u>|</p>|</o>).*(?=</f>|</e>|<e>|<t>|<s>|<l>|<u>|<p>|<o>)":"\1"
or:

Code: Select all

"(?siU)(?<=<f>|<e>|</e>|</t>|</s>|</l>|</u>|</p>|</o>).*(</f>|</e>|<e>|<t>|<s>|<l>|<u>|<p>|<o>)":"\1"
without affecting the end result.

As it turned out, the workaround for this also indicated the culprit: you can't have two lookarounds in the same expression (or string, I'm not sure yet). One will do, but if you have, say, both a positive lookbehind and a positive lookahead (like I did), it will mess up the result. I didn't throughly test why this happens and if the lookarounds have to be different or same (e.g. both positive or one positive and the other negative, both lookaheads/lookbehinds or one lookahead and the other lookbehind), but what it absolutely clear is that other regex testing sites or software do not seem to have this problem, as they output the desired result without any fuss whatsoever...

NOTE: I wanted to delete everything except what's between certain tags (thus the general </tag>.*<tag> form, as opposed to <tag>.*</tag> form).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Do alternate positive lookbehinds work in Rainmeter?

Post by jsmorley »

Glad you got it working...
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Do alternate positive lookbehinds work in Rainmeter?

Post by Yincognito »

jsmorley wrote: February 28th, 2019, 2:46 pm Glad you got it working...
I'm glad too, it seems this will not "end in tears" either. :D But then, should two (opposite?) lookarounds in the same expression be an issue, after all? Just asking...
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth