Skip to content

Instantly share code, notes, and snippets.

@X-Raym
Created October 21, 2024 18:20
Show Gist options
  • Save X-Raym/d222bc5e0a92c2333d23b4dc912ab66e to your computer and use it in GitHub Desktop.
Save X-Raym/d222bc5e0a92c2333d23b4dc912ab66e to your computer and use it in GitHub Desktop.
Python regex match to list / array
import re
str = "ab-ab"
regex = r"(\w+)\-(\w+)"
matches = re.search( regex, str )
print( list(matches.groups()) )
## ['ab', 'ab']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment