我想在文本字段上使用正则表达式验证公式。这里是纯正则表达式:
^(?!(?:D*d){7})d+(.d{1,2})?$
当我在regex在线工具中测试这个表达式时(例如:https://regex101.com/)一切都很好。但当我尝试在Orbeon中使用它作为验证器时,如下所示:
matches(string(.), '^(?!(?:D*d){7})d+(.d{1,2})?$') or xxf:is-blank(string(.))
我收到错误"XPath表达式不正确"。
当我从regex前瞻部分删除时,我可以使用它。
matches(string(.), '^d+(.d{1,2})?$') or xxf:is-blank(string(.))
Orbeon Forms是否支持regex前瞻性?Regex前瞻:https://www.regular-expressions.info/lookaround.html
在不进行前瞻的情况下重新编写表达式。它匹配不超过6位的字符串。
使用
^(d{1,4}(.d{1,2})?|d{5}(.d)?|d{6})$
查看验证
解释
NODE EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
( group and capture to 1:
--------------------------------------------------------------------------------
d{1,4} digits (0-9) (between 1 and 4 times
(matching the most amount possible))
--------------------------------------------------------------------------------
( group and capture to 2 (optional
(matching the most amount possible)):
--------------------------------------------------------------------------------
. '.'
--------------------------------------------------------------------------------
d{1,2} digits (0-9) (between 1 and 2 times
(matching the most amount possible))
--------------------------------------------------------------------------------
)? end of 2 (NOTE: because you are using a
quantifier on this capture, only the
LAST repetition of the captured pattern
will be stored in 2)
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
d{5} digits (0-9) (5 times)
--------------------------------------------------------------------------------
( group and capture to 3 (optional
(matching the most amount possible)):
--------------------------------------------------------------------------------
. '.'
--------------------------------------------------------------------------------
d digits (0-9)
--------------------------------------------------------------------------------
)? end of 3 (NOTE: because you are using a
quantifier on this capture, only the
LAST repetition of the captured pattern
will be stored in 3)
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
d{6} digits (0-9) (6 times)
--------------------------------------------------------------------------------
) end of 1
--------------------------------------------------------------------------------
$ before an optional n, and the end of the
string