JSON numbers Regular Expression

后端 未结 3 1429
长发绾君心
长发绾君心 2021-02-14 04:59

I\'m trying to write a regular expression for strings that are numbers in JSON. I\'m still new to writing Regular expressions, I found a diagram of a machine for JSON numbers h

3条回答
  •  暖寄归人
    2021-02-14 05:52

    For reference, here's the "number" diagram from http://www.json.org/fatfree.html:

    JSON number

    The regex that should match this is:

    -?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?
    

提交回复
热议问题