regex - Remove numbers except that are before the first underscores in R with gsub
问题描述
I have this list:
l <- c("F1_6346346346_TrainTest_53453465.rds", "F1_64575687357_FunctionTest_747434534.rds", "F3F4_546345647678_TrainTest_453463654.rds"
I would like to have somethins like this:
l <- c("F1_TrainTest", "F1_FunctionTest", "F3F4_TrainTest")
I have tried with 'gsub', but I am dummy with regular expressions and I haven`t been able to achieve this.
Thank you in advance!
解决方案
You can use this regex
_+\d+_*
_
- Matches_
one or more time.\d+
- Matches digits0 to 9
one or more time.-*
- Matches_
zero or more time.
推荐阅读
- xml - 使用 XPATH 将 XML 拆分为 5 个块
- azure-service-fabric - 服务结构失败并显示服务状态:fabric:/testsfApplication/tessf 未准备好,没有容器正在运行
- javascript - 如何在 chrome 中打开我的项目链接
- css - CSS 表格行和单元格宽度
- npm - npm 安装失败 - 角度 cli
- vba - 在另一个 Sub 中调用时脚本不解析单元格,excel Vba
- javascript - 显示从数据库中选择的值
- javascript - 动态创建具有唯一名称的多个 wavesurfer 对象
- amazon-web-services - 我们如何每天使用 Lambda 将文件从 S3 移动到 EC2?
- java - 检索 cookie 并在后续的 POST 请求中发送