Checking whole string with a regex

前端 未结 5 1784
醉话见心
醉话见心 2020-11-22 08:34

I\'m trying to check if a string is a number, so the regex \"\\d+\" seemed good. However that regex also fits \"78.46.92.168:8000\" for some reason, which I do not want, a l

5条回答
  •  攒了一身酷
    2020-11-22 08:50

    \d+ matches any positive number of digits within your string, so it matches the first 78 and succeeds.

    Use ^\d+$.

    Or, even better: "78.46.92.168:8000".isdigit()

提交回复
热议问题