diff --git a/src/Artemis.Core/DefaultTypes/Conditions/Operators/StringMatchesRegexConditionOperator.cs b/src/Artemis.Core/DefaultTypes/Conditions/Operators/StringMatchesRegexConditionOperator.cs new file mode 100644 index 000000000..8b2c425c7 --- /dev/null +++ b/src/Artemis.Core/DefaultTypes/Conditions/Operators/StringMatchesRegexConditionOperator.cs @@ -0,0 +1,20 @@ +using System.Text.RegularExpressions; + +namespace Artemis.Core.DefaultTypes { + internal class StringMatchesRegexConditionOperator : ConditionOperator + { + 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); + } + } +} diff --git a/src/Artemis.Core/Services/Registration/ConditionOperatorService.cs b/src/Artemis.Core/Services/Registration/ConditionOperatorService.cs index 2c009b33d..a296efd4f 100644 --- a/src/Artemis.Core/Services/Registration/ConditionOperatorService.cs +++ b/src/Artemis.Core/Services/Registration/ConditionOperatorService.cs @@ -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