Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions libraries/AdaptiveExpressions/BuiltinFunctions/IsMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,11 @@ private static EvaluateExpressionDelegate Evaluator()
return FunctionUtils.ApplyWithError(
args =>
{
var value = false;
string error = null;
var regex = CommonRegex.CreateRegex(args[1].ToString());
var inputString = args[0]?.ToString() ?? string.Empty;
var value = regex.IsMatch(inputString);

string inputString = args[0]?.ToString();
if (string.IsNullOrEmpty(inputString))
{
value = false;
error = "regular expression is empty.";
}
else
{
var regex = CommonRegex.CreateRegex(args[1].ToString());
value = regex.IsMatch(inputString);
}

return (value, error);
return (value, null);
}, FunctionUtils.VerifyStringOrNull);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,8 @@ public class ExpressionParserTests
Test(@"isMatch('1', '\\d{1}')", true), // "\d" (match [0-9])
Test(@"isMatch('12.5', '[0-9]+(\\.5)')", true), // "\." (match .)
Test(@"isMatch('12x5', '[0-9]+(\\.5)')", false), // "\." (match .)
Test("isMatch('', '([0-9])')", false), // empty string
Test("isMatch(nullObj, '([0-9])')", false), // null object
#endregion

#region type checking
Expand Down