How to write this regular expression in Lua?

前端 未结 2 1588
终归单人心
终归单人心 2021-01-05 03:26

I\'m new to the Lua regex equivalence features, I need to write the following regular expression, which should match numbers with decimals

\\b[0-9]*.\\b[0-9         


        
2条回答
  •  余生分开走
    2021-01-05 03:43

    "%d*%.?%d+" will match all such numbers in decimal format (note that that's going to miss any signed numbers such as -1.1 or +3.14). You'll need to come up with another solution to avoid instances that end with ], such as removing them from the string before looking for the numbers:

    local pattern = "%d*%.?%d+"
    local clean = string.gsub(orig ,pattern .. "%]", "")
    return string.gmatch(clean, pattern)
    

提交回复
热议问题