I can't for the life of me understand why the following regex can't match 4 floats. there is a couple of rules for the way theese floats can be written.
- the float ranges from 0 to 1
- you can skip the first digit if its 0
- there is an unlimited number of digits after the period.
Theese are valid floats
- 1
- 1.0
- 0.0
- .0
- 0.123
- .123
Now for the code I've tried amongst others
string input = " 0 0 0 .4";
string regex = @"[0-1]*(\.[0-9]*)*\s[0-1]*(\.[0-9]*)*\s[0-1]*(\.[0-9]*)*\s[0-1]*(\.[0-9]*)*";
Regex r = new Regex(regex, RegexOptions.Compiled);
Match m = r.Match(input);
m.Value Returns " 0 0 0" where i'd expect it to return "0 0 0 .4"
I've tried
[0-1]{0,1}(\.[0-9]*)*\s[0-1]{0,1}(\.[0-9]*)*\s[0-1]{0,1}(\.[0-9]*)*\s[0-1]{0,1}(\.[0-9]*)*
aswell but it looks like .net does not cope well with the {0,1} syntax (or I am just using it wrong)
I've tried looking at http://www.regular-expressions.info/reference.html and the {0,1} should be valid to my understanding atleast.
I managed to make a regex that matched the string in the little regex matcher tool I have at my disposal, but that regex did not work with the .net Regex class
UPDATE
I'm using the regex in conjunction with a Tokenizer parsing a larger document.
Combineing what Pavel Minaev and psasik wrote the following regex made an expected match
([0,1]|([0,1]?\.[0-9]+))\s([0,1]|([0,1]?\.[0-9]+))\s([0,1]|([0,1]?\.[0-9]+))\s([0,1]|([0,1]?\.[0-9]+))
The following matches the actual float
([0,1]|([0,1]?\.[0-9]+))