Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • You could greedily match everything except a dash ([^-]*), but that would get you in trouble if the actual name contains a dash. But since Youtube IDs always have 11 characters, maybe match everything up to dash + 11 characters + .mp4? Commented May 31, 2024 at 9:51
  • 1
    @DonHolgo The YouTube video ID is not guaranteed to be 11 characters long. Related: webapps.stackexchange.com/q/54443 Commented May 31, 2024 at 18:14
  • @Kusalananda It's not guaranteed to remain 11 characters long, but for existing downloads (as in the OP's case) I think it's safe to use that length. Commented May 31, 2024 at 18:39
  • 1
    If we cannot assume the last 11 characters before the the dot preceding the extension will always be the id, or that the same separator wil always separate the [truncated] title from the id, it's inherently impossible to do this reilably. Unless of course by doing something overly involved for the task such as calling Youtube's API and implementing some robust enough logic to check if the possible id actually matches the downloaded video. Commented May 31, 2024 at 23:50