简体   繁体   中英

C# Regex decimal number split from complex string

I need to match with regex a string format like this:

94.5-97.8

93-95

94/97

55.5/77.9

Using this regex it works:

([0-9]{2}[.,]?([0-9]{1})?)(-||/)([0-9]{2}[.,]?([0-9]{1})?)

but I get a regex.Groups result like(testing 94.5-97.8)

[0] --> 94.5-97.8
[1] --> 94.5
[2] --> 5
[3] --> -
[4] --> 97.8
[5] --> 8

What I need to do is (using a regex pattern) to obtain a regex.Groups like this:

[0] --> 94.5-97.8
[1] --> 94.5
[2] --> 97.8

Is it possibile?

I'm using C# and.Net Core 2.2.

UPDATE

If you put a down vote please, add the comment(with your name) of WHY you consider this question not usefull.

Round brackets defines your groups in case of grouping. So getting rid of that would make it works

([0-9]*[.,]?[0-9]?)[-,\/]([0-9]*[.,]?[0-9]?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM