I am trying to match the following sequence, line by line:
- start of line
- maybe some space
- the
Kdstring - at least one space, maybe more
- either 3 or 4
floatnumbers whose format may be messy - maybe some space
- end of line
The problem is that the 4th sample is also captured even though it has 5 numbers in it.
Pattern:
^\s*Kd\s+.*(?:[-+]?0*\d*\.?\d*){3,4}$
Samples:
Kd 1.0 0.1 0.0
Kd .0 4. 01.
Kd .0 4. 01. 01.
Kd .0 4. 01. 01. 01.
Kd 1.0 0.1 0.0 0.0
Kd 1.0 0.1 0.0
Expected captures:
- 1.0, 0.1, 0.0
- .0, 4., 01.
- .0, 4., 01., 01.
- failure
- 1.0, 0.1, 0.0, 0.0
- 1.0, 0.1, 0.0
Question:
What am I doing wrong in the regex so it also matches lines with more than 4 floats in them?