It is currently April 26th, 2024, 9:27 am

RegExpSubstitute trouble (again)

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExpSubstitute trouble (again)

Post by jsmorley »

To demonstrate what I was just talking about, consider this:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureString]
Measure=String
String=The color is red right now

[MeasureReplace]
Measure=String
String=[MeasureString]
DynamicVariables=1
RegExpSubstitute=1
Substitute="red":"blue"

[MeasureExtractRed]
Measure=String
String=[MeasureString]
DynamicVariables=1
RegExpSubstitute=1
Substitute=".*(red).*":"\1"

[MeasureExtractColor]
Measure=String
String=[MeasureString]
DynamicVariables=1
RegExpSubstitute=1
Substitute="The color is (.*) right now":"\1"
[MeasureReplace] will simply find any occurrence of "red" and replace it with "blue". You end up with:

The color is blue right now

[MeasureExtractRed] will find, but skip and throw away, anything other than "red", anything before or after it, and just return:

red

[MeasureExtractColor] will find the pattern "The color is ", then capture all characters until it sees " right now" and will return:

red
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: RegExpSubstitute trouble (again)

Post by StArL0rd84 »

So i found a example of yours that did work.
And i thank you for going into details and explaining it clearly for me, Learned a lot here.

Perfered the ones with \1, \2, \3 ... in the "Replace with" bit of the Substitute.
Easier to understand the pattern of characters :D

I will save this thread for when i need to use RegExpSubstitute again.
([mWorkTime] = 1 ? #Work# : ([mEnergyLoss:%] >= 70% ? #Chillmode# : </>))