Search code examples
javadroolsbusiness-rules

Drools Regex to Match Non-Alpha


According to the Drools Documentation, I should be able to match the following regex in a rule, since the matches operator

"Matches a field against any valid Java Regular Expression."

However,

$firstName : String(value matches "[^A-Za-z]") from $person.name.firstName

results in an error when attempting to evaluate the rule. What am I missing here?

Edit - originally had "contains" instead of "matches" in the expression. This was a type-o made when re-typing an expression similar to the one I'm working with.


Solution

  • The link contains the text The Operator matches Matches a field against any valid Java Regular Expression.

    $firstName : String(this matches ".*[^A-Za-z].*") from $person.name.firstName
    

    Note that the word is "matches" and not "find"!

    Edit

    And you cannot use "value" with String, there's no such method.