regular expression: a line of string contains only float numbers and tab/spaces

前端 未结 3 1258
悲&欢浪女
悲&欢浪女 2020-12-21 14:07

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

3条回答
  •  甜味超标
    2020-12-21 14:57

    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.

提交回复
热议问题