javascript - 如何仅获取点的正则表达式?
问题描述
在这里我有一个图像,这个 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");
}
}
解决方案
尝试这个。
imageName.match(/^[\.]+[a-zA-Z0-9]{1,}$/)
如果您的文件可能没有扩展名,那么
imageName.match(/^[\.]+[a-zA-Z0-9]{0,}$/)
推荐阅读
- swift - NavigationView 弹回根目录,省略中间视图
- python - 如何锁定一些行以在 Django 中插入?
- reactjs - 而不是从数组中删除项目,它被设置为未定义
- mysql - PHPMYADMIN | 我们如何在两个不同的 MySQL 数据库中同步两个表(在同一台服务器内)?
- vue.js - 路由器推送后 Nuxt 正在重新加载页面
- css - Bootstrap Dropdown 出现在其他元素的后面
- reactjs - 是什么导致错误:此代码中的重新渲染过多?
- sql - 执行以下 Oracle 查询时出错
- amazon-web-services - 将 docker Image 推送到 AWS ECR 时出现标记问题
- reactjs - 单击表单按钮时,Ant Design 表单元素未提交