Skip to content

Instantly share code, notes, and snippets.

@xjxckk
Last active December 16, 2021 12:19
Show Gist options
  • Save xjxckk/4376ba5ddc0cfa480e2c349270664eca to your computer and use it in GitHub Desktop.
Save xjxckk/4376ba5ddc0cfa480e2c349270664eca to your computer and use it in GitHub Desktop.
Regex positive lookbehind to capture string after prefix (Python)
import regex
url = 'https://gfycat.com/HeftyHonoredHadrosaurus'
prefix = 'https://gfycat.com/'
# https://gfycat.com/HeftyHonoredHadrosaurus to HeftyHonoredHadrosaurus
slug = regex.search(rf'(?<={prefix})\w+', url).group()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment