Regex for parsing version number

前端 未结 4 1647
失恋的感觉
失恋的感觉 2021-01-29 06:37

How can I write a regex for parsing version numbers. I want to match numbers like: 1.000, 1.0.00, 1.0.0.000 but not integers 1

4条回答
  •  一个人的身影
    2021-01-29 06:58

    Clarification: I'm assuming you want to parse the numbers, not just match them.

    Why use regexes when a simple split will work just fine?

    '1.3.4.*'.split('.') # => ['1', '3', '4', '*']

    If you want to ensure that there is at least one dot in the string, check the array length to ensure it is larger than 1.

提交回复
热议问题