Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

VB
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
Posted
Updated 22-Feb-18 4:21am
Comments
Richard Deeming 23-Feb-18 10:47am    
Different regex engines support different things. It looks like you're using the default "flavour" of regex on that site, which is pcre (PHP).

You need to test against something that's closer to .NET's syntax. Javascript is probably the closest; it doesn't support everything that .NET does, but .NET should support everything that Javascript does.

Regular Expression Language - Quick Reference[^]

* 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.
 
Share this answer
 
Comments
fallen2080 22-Feb-18 10:38am    
(?!) works as a (*FAIL) replacement, but I can not find a substitution for (*SKIP) in VB.NET. This appears to be the cause of the error I was getting.
phil.o 22-Feb-18 10:46am    
I do not know what (*SKIP) is supposed to match. All I can say is that it is not a function which is recognized by .NET's regular expression engine. Could you describe with a plain phrase what it is supposed to match?
fallen2080 22-Feb-18 11:35am    
(*SKIP) acts like (*PRUNE), except that if the pattern is unanchored, the bumpalong advance is not to the next character, but to the position in the subject where (*SKIP) was encountered
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.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900