I need t check every line of a file for the following pattern: - 14 Values seperated by an irregular number of spaces. - Values may be negative (-), decimal seperator is a dot followed by maximum one digit - The line ends with several spaces
here is a开发者_开发知识库n 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!
This should do it:
/^(-?\d+(\.\d)?\s+){14}$/
Edit: Start and end tags as added by Gumbo.
Try this regular expression:
/^(-?\d+(\.\d)? +){14}$/m
In multiline mode, the ^
and $
match the start and end of the line respectively. -?
is for the optional minus sign, \d+(\.\d)?
is for the number with optional single decimal place, and +
(space plus +
) is for the separating and trailing spaces. That pattern is then repeated exactly 14 time ((…){14}
).
精彩评论