regex - Orbeon Forms - 验证正则表达式前瞻
问题描述
我想在文本字段上使用正则表达式验证公式。这是纯正则表达式:
^(?!(?:\D*\d){7})\d+(\.\d{1,2})?$
当我在正则表达式在线工具(例如: https ://regex101.com/)中测试这个表达式时,一切正常。但是当我尝试像这样在 Orbeon 中使用它作为验证器时:
matches(string(.), '^(?!(?:\D*\d){7})\d+(\.\d{1,2})?$') or xxf:is-blank(string(.))
我收到错误“不正确的 XPath 表达式”。
当我从正则表达式前瞻部分中删除时,我能够使用它。
matches(string(.), '^\d+(\.\d{1,2})?$') or xxf:is-blank(string(.))
Orbeon Forms 是否支持正则表达式前瞻?正则表达式前瞻: 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
推荐阅读
- node.js - 使用 Firebase 功能进行购买验证后无法更新 Firestore 的文档
- datetime - 如何在 AutoHotKey 中用 datetime 直观地进行加法操作?
- python - 如何在geodash2(Python)中将纬度和经度编码为一个值?
- jsp - JSP 中的内存泄漏
- reactjs - React-router:如何在不使用链接的情况下输入直接路径
- sql - 如何复制属于一个id的多行,并添加到postgreSQL中的所有其他id
- composer-php - Composer 需要本地和 github 存储库
- react-native - 如何将按钮和选项卡导航器放在同一页面上?
- ios - 对从未在类外读取的变量使用 setter 函数是否有缺点?
- node.js - GKE Ingress 不会正确重写路径