Skip to content

Instantly share code, notes, and snippets.

@DenisCarriere
Last active August 29, 2015 13:56
Show Gist options
  • Save DenisCarriere/9217806 to your computer and use it in GitHub Desktop.
Save DenisCarriere/9217806 to your computer and use it in GitHub Desktop.
import re
# Input
string = '3d6+2'
# Regex Pattern
pattern = re.compile(r'(?P<multiplier>\d+)d(?P<die>\d+)m?(?P<math>\D)?(?P<modifier>\d+)?')
match = pattern.match(string)
# Attributes
multiplier = match.group('multiplier')
die = match.group('die')
math = match.group('math')
modifier = match.group('modifier')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment