coffeeak
coffeeak

Reputation: 3120

How to split this range of negative numbers

I have this "-6--15" and I want to split this into -6 and -15.

Here is my code in C#:

string[] groups = Regex.Split("-6--15",@"\d+\-{1}");

But it returns - and -15.

Help!

Upvotes: 0

Views: 921

Answers (1)

Ulugbek Umirov
Ulugbek Umirov

Reputation: 12797

Use the following:

string[] groups = Regex.Split("-6--15", @"(?<=\d)-");

Explanation:

(?<=\d)-

Regular expression visualization

Demo

Upvotes: 5

Related Questions