New IfMatchActions
Posted: January 5th, 2014, 4:37 pm
We have added new IfMatchAction options. These can be used on any measure, allowing you compare the string value of the measure with a PCRE Regular Expression. The comparison in IfMatch will be "true" if the regular expression succeeds, and "false" if it does not.
Actions can then be taken based on IfMatchAction (true) or IfNotMatchAction (false).
There can be as many IfMatch / IfMatchAction / IfNotMatchAction sets as you need, by appending a number. IfMatch2... / IfMatchAction2... / IfNotMatchAction2...
As with IfActions, the action is only fired once when the result becomes "true" or "false". An additional IfMatchMode option can be set to "1" to have the actions fire on each update of the measure.
Examples:
Logical OR and AND testing can be done in the regular expression, using the | character to support OR and Lookahead Assertions (?=..) to support AND.
Note that any regular expression reserved characters, which are . ^ $ * + ? ( ) [ { \ |, must be escaped with \ when used as a literal in IfMatch.
Other IfMatch Eamples:
String=Hello World
IfMatch=(?=.*Hello)(?=.*World) AND order independent
IfMatch=Hello.*World AND order dependent
IfMatch=Hello|World OR
String=Red Green Blue
IfMatch=(?=.*Red)(?=.*Green)|Blue "(1 AND 2) order independent OR 3"
String=Red Green Blue Orange
IfMatch=(?=.*Red)(?=.*Green)|(?=.*Blue)(?=.*Orange) "(1 AND 2) order independent OR (3 AND 4) order independent"
IfMatch=Red Green|Blue Orange "(1 AND 2) order and position dependent OR (3 AND 4) order and position dependent"
String=net internet
IfMatch=\bnet\b Use Word Boundary to match on net but not on internet
String=there was an error
IfMatch=error IfMatchAction will fire as it is "true"
String=everything went fine
IfMatch=error IfNotMatchAction will fire as it is "false"
More help:
Just tons of manuals, tutorials, guides, tools and other help for regular expressions can be found at Regular Expression Options in Rainmeter.
Actions can then be taken based on IfMatchAction (true) or IfNotMatchAction (false).
There can be as many IfMatch / IfMatchAction / IfNotMatchAction sets as you need, by appending a number. IfMatch2... / IfMatchAction2... / IfNotMatchAction2...
As with IfActions, the action is only fired once when the result becomes "true" or "false". An additional IfMatchMode option can be set to "1" to have the actions fire on each update of the measure.
Examples:
Code: Select all
[MeasureMyString]
Measure=String
String=Hello World
IfMatch=.*World.*
IfMatchAction=[!Log "World was found"]
IfNotMatchAction=[!Log "World was not found"]
Code: Select all
[MeasureWeatherConditions]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWeatherParent]
StringIndex=5
IfMatch=(?i)sunny|fair
IfMatchAction=[!SetOption MeterConditions FontColor #Yellow#]
IfNotMatchAction=[!SetOption MeterConditions FontColor #Grey#]
Note that any regular expression reserved characters, which are . ^ $ * + ? ( ) [ { \ |, must be escaped with \ when used as a literal in IfMatch.
Other IfMatch Eamples:
String=Hello World
IfMatch=(?=.*Hello)(?=.*World) AND order independent
IfMatch=Hello.*World AND order dependent
IfMatch=Hello|World OR
String=Red Green Blue
IfMatch=(?=.*Red)(?=.*Green)|Blue "(1 AND 2) order independent OR 3"
String=Red Green Blue Orange
IfMatch=(?=.*Red)(?=.*Green)|(?=.*Blue)(?=.*Orange) "(1 AND 2) order independent OR (3 AND 4) order independent"
IfMatch=Red Green|Blue Orange "(1 AND 2) order and position dependent OR (3 AND 4) order and position dependent"
String=net internet
IfMatch=\bnet\b Use Word Boundary to match on net but not on internet
String=there was an error
IfMatch=error IfMatchAction will fire as it is "true"
String=everything went fine
IfMatch=error IfNotMatchAction will fire as it is "false"
More help:
Just tons of manuals, tutorials, guides, tools and other help for regular expressions can be found at Regular Expression Options in Rainmeter.