首页 > 解决方案 > 如何仅获取点的正则表达式?

问题描述

在这里我有一个图像,这个 imageName 只有点( )如果 imageName 只有点,...............jpg我得到的 imageName 只有点(imageNameWithoutExtension参见 cosole),所以我只想要点正则表达式,所以我可以只与点正则表达式与名为 imageName 的点进行比较,如何获取点正则表达式?

重命名文件.component.ts

updateFileName(){

  console.log(imageName);  // ...............jpg 
  var imageArray = imageName.split('.');
  var imageExtension = imageArray.pop();
  var imageNameWithoutExtension = imageArray.join('.');  
  console.log(imageNameWithoutExtension);  // ...............

   imageNameWithoutExtension.replace(^([,.\d]+)([,.]\d{2})$); i tried this but it gives error, how to use regex or make regex I dont know 

  'image name with only dots' // hot to get regex of only dots

  if(imageNameWithoutExtension == 'image name with only dots'){
    console.log("image name with only dots so not allowed to rename");

  }else{
    console.log("image name with not only dots so allow to rename");
  }
}

标签: javascriptregexangular

解决方案


尝试这个。

imageName.match(/^[\.]+[a-zA-Z0-9]{1,}$/)

如果您的文件可能没有扩展名,那么

imageName.match(/^[\.]+[a-zA-Z0-9]{0,}$/)

推荐阅读