It is currently March 28th, 2024, 11:44 pm

[FIXED BUG] RegEx not being parsed correctly with Substitute.

Report bugs with the Rainmeter application and suggest features.
User avatar
redsaph
Posts: 30
Joined: October 24th, 2013, 8:15 am

[FIXED BUG] RegEx not being parsed correctly with Substitute.

Post by redsaph »

Hello,

I use the following RegEx statement to trim down the title of a song and use the first capture group

Code: Select all

\1
in order to do it:

Code: Select all

^(.+) (-.+|((\(|\[)?\s?(remix|Remix|REMIX|with|With|WITH|feat|Feat|FEAT|ft|Ft|FT|(w|W)\/).+))+$
Now, I took Kendrick Lamar's song Loyalty which is titled as

Code: Select all

LOYALTY. FEAT. RIHANNA.
This should return

Code: Select all

LOYALTY.
Why this isn't working for RegExpSubtitute and Subtitute when various online testers and RainRegExp verify it works?
Last edited by redsaph on October 13th, 2017, 10:14 am, edited 3 times in total.
Rainmeter-er since 2013 :welcome: | My DeviantART
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: RegEx not being parsed correctly with Substitute?

Post by balala »

I think something is not ok with the posted regular expression: it has mor opened parenthesis then closed ones.
But first, please post the whole code. It'd be much simpler to help.
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: RegEx not being parsed correctly with Substitute?

Post by ikarus1969 »

balala wrote:I think something is not ok with the posted regular expression: it has mor opened parenthesis then closed ones.
That's because one of the open parenthesis is escaped with the backslash character.

@redsaph:
what i would try is to replace the regular expression by:

Code: Select all

(?siU)^(.+) (-.+|((\(|\[)?\s?(remix|with|feat|ft|w\/).+))+$
which would simplify it a little bit.
the i in (?siU) means "ignore case" so you don't have to code all the possible different cases like "remix" "REMIX", etc.

it work's in RainRegExp too.

But i agree with balala; it would be much easier to help with the code of the whole skin. Or at least a test skin we can have a look at.
User avatar
redsaph
Posts: 30
Joined: October 24th, 2013, 8:15 am

Re: RegEx not being parsed correctly with Substitute?

Post by redsaph »

Hi guys, thanks for the quick response. Here's the simple example, maybe you could see it too:

Code: Select all

[Rainmeter]
Update=50
Author=Redsaph
AccurateText=1

[mTitle1]
Measure=Plugin
Plugin=SpotifyPlugin.dll
Type=TrackName
RegExpSubstitute=1
Substitute="^(.+) (-.+|((\(|\[)?\s?(remix|Remix|REMIX|with|With|WITH|feat|Feat|FEAT|ft|Ft|FT|(w|W)\/).+))+$":"\1"

; =================================================
; Meters

[Background]
Meter=Image
X=0
Y=0
W=700
H=100
SolidColor=0,0,0,180
UpdateDivider=-1

[Title]
Meter=String
Y=0
X=0
DynamicVariables=1
Text=[mTitle1]
FontFace=Segoe UI
FontSize=36
FontColor=255,255,255,255
AntiAlias=1
StringAlign=Left
@ikarus1969 Thank you very much for simplifying my RegEx :) I didn't know that existed!
Rainmeter-er since 2013 :welcome: | My DeviantART
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: RegEx not being parsed correctly with Substitute?

Post by ikarus1969 »

I admit i have no idea why your regexp doesn't work :confused:
Maybe someone else can help?!
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: RegEx not being parsed correctly with Substitute?

Post by balala »

I agree with ikarus1969 and also don't know what's happening, why that Substitute option doesn't work. A regular expression tester indeed returned the appropriate string, so, I have no idea what's happening... :o
But I'd suggest another substitution: Substitute="(?siU)^(.*)\s*(remix|with|feat|ft)\.\s*(.*)$":"\1". As ikarus1969 said, there's no need to list all those words, written uppercase and lowercase and so on. The (?siU) can help in these cases.
User avatar
redsaph
Posts: 30
Joined: October 24th, 2013, 8:15 am

Re: RegEx not being parsed correctly with Substitute.

Post by redsaph »

Thanks Ikarus and Balala! I hope someone from the development team can shed some light on this issue.
Rainmeter-er since 2013 :welcome: | My DeviantART
User avatar
Brian
Developer
Posts: 2674
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: [BUG] RegEx not being parsed correctly with Substitute.

Post by Brian »

The problem stems from a fix we did back in the r2414 or r2416 builds. We are evaluating a fix and will get back to you. Rainmeter versions prior to r2414 worked okay (for this particular issue).

-Brian
User avatar
Brian
Developer
Posts: 2674
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: [BUG] RegEx not being parsed correctly with Substitute.

Post by Brian »

r2944 should have fixed this issue.

-Brian
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: [BUG] RegEx not being parsed correctly with Substitute.

Post by ikarus1969 »

Brian wrote:r2944 should have fixed this issue.

-Brian
this issue is fixed, thank you!

i used the following to test (shortened regex):

Code: Select all

[Rainmeter]
Update=1000
Author=Redsaph
AccurateText=1

; [mTitle1]
; Measure=Plugin
; Plugin=SpotifyPlugin.dll
; Type=TrackName
; RegExpSubstitute=1
; Substitute="^(.+) (-.+|((\(|\[)?\s?(remix|Remix|REMIX|with|With|WITH|feat|Feat|FEAT|ft|Ft|FT|(w|W)\/).+))+$":"\1"

[mTitle1]
Measure=STRING
String=LOYALTY. FEAT. RIHANNA.
RegExpSubstitute=1
; Substitute="^(.+) (-.+|((\(|\[)?\s?(remix|Remix|REMIX|with|With|WITH|feat|Feat|FEAT|ft|Ft|FT|(w|W)\/).+))+$":"\1"
Substitute="(?siU)^(.+) (-.+|((\(|\[)?\s?(remix|with|feat|ft|w\/).+))+$":"\1"

; =================================================
; Meters

[Background]
Meter=Image
X=0
Y=0
W=700
H=100
SolidColor=0,0,0,180
UpdateDivider=-1

[Title]
Meter=String
Y=0
X=0
DynamicVariables=1
measurename=mTitle1
; Text=[mTitle1]
FontFace=Segoe UI
FontSize=36
FontColor=255,255,255,255
AntiAlias=1
StringAlign=Left