Regular expression [Any number]

后端 未结 4 514
一个人的身影
一个人的身影 2021-02-02 07:09

I need to test for \"[any number]\" in a string in javascript. how would i match it?

Oh, \"[\" and \"]\" also need to be matched.

so string like \"[1]\" or \"[1

4条回答
  •  爱一瞬间的悲伤
    2021-02-02 07:24

    UPDATE: for your updated question

    variable.match(/\[[0-9]+\]/);
    

    Try this:

    variable.match(/[0-9]+/);    // for unsigned integers
    variable.match(/[-0-9]+/);   // for signed integers
    variable.match(/[-.0-9]+/);  // for signed float numbers
    

    Hope this helps!

提交回复
热议问题