什么是 "regex" 只检测“.”

What is the "regex" to only detect "."

我正在使用 p5.js 的库在 javascript 上构建一个计算器。 我想为数字制作“。”(昏迷)

wut 是“.”的正则表达式。只有

我试过/^[]\.[]*$//^-?\d*[.]?\d*$/但还是没检测到

  if(mouseX > 110 &&///.
     mouseX < 190 &&
     mouseY < 570 &&
     mouseY > 490)
  {
 if(/^[]\.[]*$/.test(numtext) == true){
 numtext = numtext.substr(0, numtext.length - 1);
 }else
  numtext = numtext + "."
  }

我希望在输入该代码后,它会在检测到 2 时删除 text.length。"s

感谢 R3step。

我没有使用 . 的正则表达式,而是使用了 str.indexOf()

如果你想看,这里是解决的代码

   if(numtext.indexOf(".") !== -1)
   {
   numtext = numtext;
   }else
   numtext = numtext + ".";
  }