You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

构建图像序列文件名正则表达式:捕获前缀、帧号及扩展名

Fixing Your Image Sequence Filename Regex

Hey there! Let's get that regex working exactly how you need it. You're already halfway there with your existing pattern—we just need to add the prefix capture group and tweak things to cover all your examples.

The Final Regex

^(.*)(\d+)\.([a-zA-Z0-9]{3,4})$

Breakdown of Each Capture Group

Let's walk through what each part does, so you understand how it fits your requirements:

  • Group 1: (.*)
    This greedily captures everything from the start of the filename up to the last sequence of digits (your frame number). It works even if your prefix has other numbers, dots, underscores, or spaces—like in img01_123.png or img 001.12.png—because the regex engine will automatically backtrack to leave the final digit sequence for the next group.
  • Group 2: (\d+)
    Captures one or more consecutive digits (your frame number), which sits right before the extension's dot—exactly what you need since the frame number is always adjacent to the extension.
  • Group 3: ([a-zA-Z0-9]{3,4})
    Captures the 3-4 character extension (letters or numbers, covering common types like png, jpg, jpeg). The \. before it ensures we only match the dot immediately preceding the extension.

Testing Against Your Examples

Let's verify it works with all your sample filenames:

  • img123.png → Group 1: img, Group 2: 123, Group 3: png
  • img.123.png → Group 1: img., Group 2: 123, Group 3: png
  • img_v01_1234.png → Group 1: img_v01_, Group 2: 1234, Group 3: png
  • img01_123.png → Group 1: img01_, Group 2: 123, Group 3: png
  • img.001.123.png → Group 1: img.001., Group 2: 123, Group 3: png
  • img 001.12.png → Group 1: img 001., Group 2: 12, Group 3: png

All cases check out! If you ever need to adjust for edge cases (like extensions with special characters), you can modify the third group's character set, but this should cover your stated requirements perfectly.

内容的提问来源于stack exchange,提问作者Spencer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:19:14