It is currently April 28th, 2024, 12:48 pm

Some questions about regular expressions

Get help with creating, editing & fixing problems with skins
phroggyy
Posts: 5
Joined: January 6th, 2013, 5:32 pm

Some questions about regular expressions

Post by phroggyy »

Hello,

I was just editing in the 10-Foot Spotify skin, and I'm now trying to accomplish two things:

1. Remove everything from "(feat." and onwards, since that takes up a ridiculous space at times
2. Splitting the string given from spotify (Artist - Song title) as to be able to manipulate each string separately

As I've understood it, the first one should be possible to solve using RegExpSubstitution = 1, in which case you could probably use $', as to replace everything after the matching string "(feat.".

However, the main problem which I'm facing is that I don't quite understand the use of RegExp and RegExpSubstitution; When i turn it on, all other substitutions mess up, so do I use \0 in some way for it to read the whole strings and substitute.

For example: How would I write

Code: Select all

"Spotify - ":""
for it to be seen correctly with RegExpSubstitution=1, or do I write separate substitution lines, one before regexp is on and one after (would that work?)?

I would be grateful for any help and explanation on RegExp, because the help page didn't help enough!
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: Some questions about regular expressions

Post by moshi »

to remove everything after (feat. use

Code: Select all

RegExpSubstitute=1
Substitute="^(.*)\(feat.*$":"\1"
there is only one Substitute line allowed in a measure. so you probably want:

Code: Select all

RegExpSubstitute=1
Substitute="^(.*)\(feat.*$":"\1","Spotify - ":""
phroggyy
Posts: 5
Joined: January 6th, 2013, 5:32 pm

Re: Some questions about regular expressions

Post by phroggyy »

moshi wrote:to remove everything after (feat. use

Code: Select all

RegExpSubstitute=1
Substitute="^(.*)\(feat.*$":"\1"
there is only one Substitute line allowed in a measure. so you probably want:

Code: Select all

RegExpSubstitute=1
Substitute="^(.*)\(feat.*$":"\1","Spotify - ":""
That works perfectly, thanks a lot! However, do you know why

Code: Select all

Substitute="[Paused]":"","Spotify - ":"","[Stopped]":"","Spotify":""," – ":"#CRLF#"
does not work when RegExpSubstitute is set to 1?

Also, if it's not too much to ask, can you please explain what the different components are, so I understand how it works so I can better apply it myself? (Such as how come it replaces "feat." even when there is no parenthesis?) :)

Again, thanks a lot!

Edit: Do you also have a solution to my other problem; splitting a string at " - "
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: Some questions about regular expressions

Post by moshi »

you'll need to escape the brackets if you use regular expressions. use \[ instead of [ etc.

no, i am not going to explain you all about regular expressions. have a look here: http://docs.rainmeter.net/manual/options#RegExp and follow the links. all are far more complete and in better English than a forum post can be.


on splitting (you'll need two measures):

Code: Select all

RegExpSubstitute=1
Substitute="^(.*)-(.*)$":"\1"
would return the first part.

Code: Select all

RegExpSubstitute=1
Substitute="^(.*)-(.*)$":"\2"
would return the second part.