Created
May 6, 2014 04:35
-
-
Save lodestone/11553367 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse(dices) | |
%r{^ | |
(?<top_or_bottom>t|b)? # Flag for finding the top or bottom dice | |
(?<tb_number>\d)? # Number of top or bottom dice | |
\[(?<dice>.*)\] # The main dice string, to be parsed later | |
(?<explode>\*)? # Reroll (explode) die rolls? (i.e. 6 on 1d6) | |
(?<plus>(\+|\-)\d+)? # Additional points to add to roll (or subtract) | |
\=? # = Target Number or range follows... | |
(?<target>.*)?$ # The target number (single 4, range 4..6, above 4+, below 4-) | |
}x =~ dices | |
die_set = eval "[" + string_to_dice_array(dice) + "]" | |
dice_pool({set: die_set, top: tb_number.to_i, plus: plus.to_i}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That is one readable regex.