如果正则表达式不匹配,则抛出流口水验证
Throw drools validation if Regex doesn't match
rule "doesnot match REGEX"
when
RuleActivator( targetMessage == "message" )
$g: Parent(name matches "^[0-9]{4}[" "][A-Z]{2}[" "][0-9]{5}[" "]")
then
insert(new ValidationError(Validation($ROOT, $g, "name"), "SSDN"));
end
目前这条规则在匹配正则表达式时会抛出错误。当此正则表达式不匹配时,我想抛出错误。
那么,流口水有什么方法吗?还是有别的办法?
使用not matches
:
The operator not matches
:
The operator returns true if the String does not match the regular expression. The same rules apply as for the matches
operator.
根据要求判断:
Position 1-4: numeric part of postal code - Position 5: blanc - Position 6-7: two uppercases (A2) - Position 8: blanc - Position 9-13: address (numeric, align to the left, to be filled up with spaces) - Position 14: blanc
您的正则表达式应如下所示:
^[0-9]{4}[ ][A-Z]{2}[ ][0-9]{5}[ ]
rule "doesnot match REGEX"
when
RuleActivator( targetMessage == "message" )
$g: Parent(name matches "^[0-9]{4}[" "][A-Z]{2}[" "][0-9]{5}[" "]")
then
insert(new ValidationError(Validation($ROOT, $g, "name"), "SSDN"));
end
目前这条规则在匹配正则表达式时会抛出错误。当此正则表达式不匹配时,我想抛出错误。 那么,流口水有什么方法吗?还是有别的办法?
使用not matches
:
The operator
not matches
:The operator returns true if the String does not match the regular expression. The same rules apply as for the
matches
operator.
根据要求判断:
Position 1-4: numeric part of postal code - Position 5: blanc - Position 6-7: two uppercases (A2) - Position 8: blanc - Position 9-13: address (numeric, align to the left, to be filled up with spaces) - Position 14: blanc
您的正则表达式应如下所示:
^[0-9]{4}[ ][A-Z]{2}[ ][0-9]{5}[ ]