如何解决我的正则表达式“量词{x,y}无效”错误? [英] How do I solve my regex "quantifier {x, y} following nothing" error?

查看:219
本文介绍了如何解决我的正则表达式“量词{x,y}无效”错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 www.regex101.com 上测试了一个Regex字符串,以查找特定模式的匹配项。当我尝试将它添加到我的VB。 NET winform,它以未处理的异常失败:



解析\b(?:TP \d {1,4} | FD \ d {1,4} | {MH\d 1,4})(* SKIP)(* FAIL)| [AZ] {1,2} {\d 1,4} \b |(PCB)\\ \\ b - 量词{x,y}什么也没有。



我尝试过的事情:



I have a Regex string that I have tested on www.regex101.com to find matches for a specific pattern. When I try to add it to my VB. NET winform, it fails with an unhandled exception:

parsing "\b(?:TP\d{1,4}|FD\d{1,4}|MH\d{1,4})(*SKIP)(*FAIL)|[A-Z]{1,2}\d{1,4}\b|(PCB)\b" - Quantifier {x,y} following nothing.

What I have tried:

Dim regexPartName As New Regex("\b(?:TP\d{1,4}|FD\d{1,4}|MH\d{1,4})(*SKIP)(*FAIL)|[A-Z]{1,2}\d{1,4}\b|(PCB)\b")

If regexECADName.IsMatch(bodyFound.Name)
'STUFF
End If

推荐答案

* 是必须的量词在之后放置它应该量化的元素。

在这两个元素中(* SKIP)(* FAIL),量词放错位置并导致他收到错误消息。



我个人使用 Expresso [ ^ ]构造并验证我的正则表达式。也许你应该尝试一下这个可以帮助你构建有效正则表达式的免费工具。



亲切。
* is a quantifier which has to be placed after the element it is supposed to quantify.
In these two elements (*SKIP) and (*FAIL), quantifiers are misplaced and lead to he error message you get.

I personnaly use Expresso[^] to construct and validate my regular expressions. Maybe you shoud have a try at this free tool which can help you building valid regular expressions.

Kindly.


解决方案1已经给你答案。

建议:使用多于1个工具测试你的RegEx,你可以看到在线正则表达式测试仪和调试器:PHP,PCRE,Python,Golang和JavaScript [ ^ ]对一个错误的表达感到满意。我通常使用最后一个链接。



只是一些有趣的链接来帮助构建和调试RegEx。

以下是RegEx文档的链接:

perlre - perldoc.perl.org [ ^ ]

以下是帮助构建RegEx并调试它们的工具的链接: br />
.NET Regex Tester - Regex Storm [ ^ ]

Expresso正则表达式工具 [ ^ ]

RegExr:Learn,Build,&测试RegEx [ ^ ]

此节目RegEx是一个很好的图表,它非常有助于理解RegEx的作用:

Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]
Solution1 already gives you the answer.
Advice: use more than 1 tool to test your RegEx, as you can see Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^] is happy with an expression which is wrong. I usually use the last link.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]


这篇关于如何解决我的正则表达式“量词{x,y}无效”错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆