首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Orbeon Forms -验证正则表达式先行

Orbeon Forms -验证正则表达式先行
EN

Stack Overflow用户
提问于 2020-07-20 20:48:40
回答 1查看 63关注 0票数 1

我想在文本字段上使用正则表达式验证公式。下面是一个纯正则表达式:

代码语言:javascript
运行
复制
^(?!(?:\D*\d){7})\d+(\.\d{1,2})?$

当我在正则表达式在线工具(例如:https://regex101.com/)中测试这个表达式时,一切正常。但当我尝试在Orbeon中使用它作为验证器时,如下所示:

代码语言:javascript
运行
复制
matches(string(.), '^(?!(?:\D*\d){7})\d+(\.\d{1,2})?$')  or xxf:is-blank(string(.))

我得到错误‘不正确的XPath表达式’。

当我从正则表达式先行部分中删除时,我就可以使用它了。

代码语言:javascript
运行
复制
matches(string(.), '^\d+(\.\d{1,2})?$')  or xxf:is-blank(string(.))

Orbeon Forms是否支持regex lookahead?正则表达式前视:https://www.regular-expressions.info/lookaround.html

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-21 04:39:05

重写表达式而不使用前视。它匹配不超过6位数字的字符串。

使用

代码语言:javascript
运行
复制
^(\d{1,4}(\.\d{1,2})?|\d{5}(\.\d)?|\d{6})$

请参阅proof

解释

代码语言:javascript
运行
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62995742

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档