But I donβt understand why the result consists of two filled empty cells: Let's try to break your regular expression.
Regex: (?=(?:....)*$)
Explanation: Lookahead (? =) For anything 4 times (?: ....) for zero or more. Just looking ahead and nothing will match zero width .
Since you are using a * quantifier that indicates zero or more, it matches the first zero width at the beginning or in the line, and also at the end of the line.
Visualize it from this snapshot of Regex101 Demo
[ ![Zero Width visualization. [2]](https://fooobar.com/undefined)
So, how can I select only those 3 separators in the middle?
I don't know C # very well, but this three-step method might work for you.
Find (\d{4}) and replace it with -\1 . The result will be -4581-4582-4583-4584 . Demo
Now replace first - with a search with ^- . The result will be 4581-4582-4583-4584 . Demo
Finally find - and separate it. Demo Used \n to replace the demo target.
Alternative Solution Inspired by Roya's answer.
Regex: (?=(?!^)(?:\d{4})+$)
Explanation:
(?= // Look ahead for (?!^) // Not the start of string (?:\d{4})+$ // Multiple group of 4 digits till end of string )

Since nothing is matched and only converse statements are used, it will determine the width of zero after a group of 4 digits.
Regex101 demo
Rahul source share