what the regular expression of a line of string containing ONLY float numbers separated with spaces or tabs. The float number can be negative, like -999.999
Let's come up with a regex for a float, and then see what we can do about the rest.
A float is:
Put that together, and we get:
/-?[0-9]+(\.[0-9]+)?([Ee][+-]?[0-9]+)?/
Now, this is pretty loose, but you can tweak it if you want to tighten it up a little. Now, for any number of these with spaces in between, it's pretty trivial:
/^(F\s+)+$/
Put it all together, we end up with:
/^(-?[0-9]+(\.[0-9]+)?([Ee][+-]?[0-9]+)?\s+)+$/
(?:-?(?:\d+(?:\.\d*)|.\d+)[ \t]*)+
is one possibility. In more readable format:
(?:
-? # Optional negative sign
(?:
\d+(?:\.\d*) # Either an integer part with optional decimal part
|
.\d+ # Or a decimal part that starts with a period
)
[ \t]* # Followed by any number of tabs or spaces
)+ # One or more times
A regex for a float would look like this: -?\d+\.?\d+
A whitespace separator looks like this: \s
Put them together, allow it to repeat, make sure the end has a float (not a separator):
((-?\d+\.?\d*)\s)*(-?\d+\.?\d*))
The escaping and \d
vs [0-9]
might change, depending on your flavor of regex.