C
C#2y ago
Sernik

regex help [Answered]

So I made a regex with little help of copilot, it looks like this:
^
(?<source>[0-7],[0-7])\s?
(?<destination>[0-7],[0-7])\s?
(?<capture>[0-7],[0-7])?
$
^
(?<source>[0-7],[0-7])\s?
(?<destination>[0-7],[0-7])\s?
(?<capture>[0-7],[0-7])?
$
It should match strings like this: "n,n > n,n x n,n" or like this: "n,n > n,n", where n is number between 0 and 7 (spaces between are optional) However when I test it here https://regex101.com/r/MMnQql/1 I get no matches The question is why? Can somebody help me?
regex101
regex101: build, test, and debug regex
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
9 Replies
ZacharyPatten
ZacharyPatten2y ago
I would recommend you make a unit test and then post the unit test here this kind of topic lends itself to test-driven-development (TDD)
Yawnder
Yawnder2y ago
You don't have any notion of <, > or x in your regex.
Sernik
Sernik2y ago
I am currently making a refactoring in my project and i have a lot of errors so i cant run my tests now
amio
amio2y ago
Dialect issue? Does that site support .NET flavor regex? oh, yes it does. If it's turned on
Yawnder
Yawnder2y ago
^(?<source>[0-7],[0-7])\s?>\s?(?<destination>[0-7],[0-7])\s?(?:x\s?(?<capture>[0-7],[0-7]))?$ Feels like it has been added relatively recently.
Sernik
Sernik2y ago
oh thanks! totally forgot about that!
Yawnder
Yawnder2y ago
You're welcome
Jayy
Jayy2y ago
this can be closed i assume
Accord
Accord2y ago
✅ This post has been marked as answered!