Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要URI模板的正则表达式(RFC6570)_Javascript_Regex_Jsonschema_Uritemplate - Fatal编程技术网

Javascript 需要URI模板的正则表达式(RFC6570)

Javascript 需要URI模板的正则表达式(RFC6570),javascript,regex,jsonschema,uritemplate,Javascript,Regex,Jsonschema,Uritemplate,我需要验证字符串以确保它是有效的。使用正则表达式应该很容易。然而,我没有找到一个——真的没有URI模板的正则表达式吗 上下文:我想在使用node.js处理的JSON模式中使用它。我想您可能会找到用Java实现RFC-6570的方法 <dependency> <groupId>com.github.fge</groupId> <artifactId>uri-template</artifactId> <ver

我需要验证字符串以确保它是有效的。使用正则表达式应该很容易。然而,我没有找到一个——真的没有URI模板的正则表达式吗


上下文:我想在使用node.js处理的JSON模式中使用它。

我想您可能会找到用Java实现RFC-6570的方法

<dependency>
    <groupId>com.github.fge</groupId>
    <artifactId>uri-template</artifactId>
    <version>yourVersionHere</version>
</dependency>

在这里参加聚会有点晚了,但由于唯一的答案并没有解决URI模板的正则表达式问题,我决定尝试一下,因为我也找不到正则表达式。这完全基于中的ABNF规则,我包括了一些ASCII艺术来映射不同的组件

^([^\x00-\x20\x7f"'%<>\\^`{|}]|%[0-9A-Fa-f]{2}|{[+#./;?&=,!@|]?((\w|%[0-9A-Fa-f]{2})(\.?(\w|%[0-9A-Fa-f]{2}))*(:[1-9]\d{0,3}|\*)?)(,((\w|%[0-9A-Fa-f]{2})(\.?(\w|%[0-9A-Fa-f]{2}))*(:[1-9]\d{0,3}|\*)?))*})*$
  \                            \_____________/ \\____________/ \\__________________/    \__________________/ /\________________/ /  \_________________________________________________________________/ //
   \                            pct-encoded /   \   operator    \\     varchar                varchar       /  modifier-level4  /                               varspec                                //
    \______________________________________/     \               \\________________________________________/                   /                                                                      //
                    literals                      \               \                varname                                    /                                                                      //
                                                   \               \_________________________________________________________/                                                                      //
                                                    \               \                        varspec                                                                                               //
                                                     \               \____________________________________________________________________________________________________________________________//
                                                      \                                                                   variable-list                                                           /
                                                       \_________________________________________________________________________________________________________________________________________/
                                                                                                                   expression
(3)目前的代码:::::::[0-9A-FAA-f-f-0-9A-FAA-FAA-f[0-9A-FAA-f[2}{2},{2},{2},{2},{2},{2}目前目前的代码:::[0-0-0-9A-9A-FAA-f-f-f[2-f-f[2},[2},[2},[2},[2},[2},[2},[2},[2},[2},[2},[2},[2},[2},[2},[2},[2},[2},[3},[3},[3},[3},[3},[3},[3},[3},[3},[1-9-9-9-9-9-9....|%[0-9A-Fa-f]{2}]*(:[1-9]\d{0,3}\*)?)*)*$ \ \_____________/ \\____________/ \\__________________/ \__________________/ /\________________/ / \_________________________________________________________________/ // \pct编码/\operator\\varchar varchar/modifier-level4/varspec// \______________________________________/ \ \\________________________________________/ / // 文字\\varname/// \ \_________________________________________________________/ // \\varspec// \ \____________________________________________________________________________________________________________________________// \变量表/ \_________________________________________________________________________________________________________________________________________/ 表达
您可以在上查看。这应该在JSON模式下工作,因为我使用的是ECMA语法。可能还可以进行一些简化,但正如我所说的,这与ABNF一致,因此如果您熟悉规范,那么应该比较容易遵循。

我认为验证URL的正则表达式模式对您适用。否事实并非如此,因为URL不允许URI模板占位符(比如大括号),那么,你不能调整URL模式吗?当然,我只是想知道是否已经有一个经过战斗验证的正则表达式了…
^([^\x00-\x20\x7f"'%<>\\^`{|}]|%[0-9A-Fa-f]{2}|{[+#./;?&=,!@|]?((\w|%[0-9A-Fa-f]{2})(\.?(\w|%[0-9A-Fa-f]{2}))*(:[1-9]\d{0,3}|\*)?)(,((\w|%[0-9A-Fa-f]{2})(\.?(\w|%[0-9A-Fa-f]{2}))*(:[1-9]\d{0,3}|\*)?))*})*$
  \                            \_____________/ \\____________/ \\__________________/    \__________________/ /\________________/ /  \_________________________________________________________________/ //
   \                            pct-encoded /   \   operator    \\     varchar                varchar       /  modifier-level4  /                               varspec                                //
    \______________________________________/     \               \\________________________________________/                   /                                                                      //
                    literals                      \               \                varname                                    /                                                                      //
                                                   \               \_________________________________________________________/                                                                      //
                                                    \               \                        varspec                                                                                               //
                                                     \               \____________________________________________________________________________________________________________________________//
                                                      \                                                                   variable-list                                                           /
                                                       \_________________________________________________________________________________________________________________________________________/
                                                                                                                   expression