mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge pull request #489 from F-Lehmann/regex
[UPDATED] Introduced String Regex Condition Operator
This commit is contained in:
commit
df3c472f7b
@ -0,0 +1,20 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes {
|
||||
internal class StringMatchesRegexConditionOperator : ConditionOperator<string, string>
|
||||
{
|
||||
public override string Description => "Matches Regex";
|
||||
public override string Icon => "Regex";
|
||||
|
||||
public override bool Evaluate(string text, string regex)
|
||||
{
|
||||
// Ensures full match
|
||||
if (!regex.StartsWith("^"))
|
||||
regex = "^" + regex;
|
||||
if (!regex.EndsWith("$"))
|
||||
regex += "$";
|
||||
|
||||
return Regex.IsMatch(text, regex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,6 +61,7 @@ namespace Artemis.Core.Services
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new StringNotContainsConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new StringStartsWithConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new StringEndsWithConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new StringMatchesRegexConditionOperator());
|
||||
|
||||
// Null checks, at the bottom
|
||||
// TODO: Implement a priority mechanism
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user