C
C#3y 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
ZacharyPatten3y 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
Yawnder3y ago
You don't have any notion of <, > or x in your regex.
Sernik
SernikOP3y 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
amio3y ago
Dialect issue? Does that site support .NET flavor regex? oh, yes it does. If it's turned on
Yawnder
Yawnder3y 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
SernikOP3y ago
oh thanks! totally forgot about that!
Yawnder
Yawnder3y ago
You're welcome
Jayy
Jayy3y ago
this can be closed i assume
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server