RegExp, which matches any string containing "0-9" and ".". and and ""
I need to check each line of the file for the following pattern: - 14 Values separated by an irregular number of spaces. - Values can be negative (-), the decimal separator is a period followed by a maximum of one digit - The line ends with multiple spaces
here is an example line:
10015 20100501 1 4.6 6.4 8.4 10.5 86.6 4.0 13.0 0.9 6.4 0.0 1007.2
Thanks!
a source to share
Try this regex:
/^(-?\d+(\.\d)? +){14}$/m
In multiline mode, ^
and $
correspond to the beginning and end of the line, respectively. -?
- for an optional minus sign, \d+(\.\d)?
for a number with an optional single decimal place, and +
(space plus +
) for separating and trailing spaces. Then this pattern is repeated exactly 14 times ( (…){14}
).
a source to share