For this particular application there's not a good fixed format to apply since (for instance) the damage roll format for a power can change based on the number of points put into it. For example, 10 points in a power might do 2d6 damage, while 15 might be d6+d8, 20 might be 2d8, etc. I've scraped a few of the barnacles off my javascript skills and started on implementing something on a plain html page for starters; it doesn't look it will be too hard to do. Just need to better understand the results I'm getting from regex exec and match functions, but I'll figure it out. GiGs said: This would be possible. Is there a reason though you need to allow players to enter these as strings. You could instead have three inputs, asking for number dice, type of dice, and bonus. You could set it up something like <input type="number" class="dice-display" name="attr_dice_number" value="1"> <span class="dice-display">d</span> <input type="number" class="dice-display" name="attr_dice_sides" value="6"> <select class="dice-display" name="attr_dice_direction"> <option value="1" selected>+</option> <option value="-1">-</option> </select> <input type="number" class="dice-display" name="attr_dice_modifier" value="0">
<!-- note: multiply the modifier by the dice_direction to get the true modifier. --> put it in a div, maybe, and then use css to set up so it displays properly. Then you simple collect all the properties of each dice roll and handle them easily. The advantage of this approach (and it is huge - non-programmers often underestimate just how important this is) is that users cannot mess up the input. Allowing for a simple text string like "1d6+1" is prone to error, and often needs a lot of programming to handle the script not breaking when unexpected text is entered (which will happen - even if just form typos).