RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(?<dice>\d*)(?<dsides>(?<separator>[\d\D])(?<sides>\d+))(?<modifier>(?<sign>[\+\-])(?<addend>\d))?
Description
D&amp;D dice: If no dice are entered, 1 can be assumed. d or D is required to indicate sides, and cannot exist without a sides digit. The modifier is optional. However, if there is a modifier, a sign and an addend must be included.
Matches
2d6+4 | 2d6 | d6+4
Non-Matches
6- | d | 2d
Author Rating: Not yet rated. Janine White
Source Janine White
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Minor correction
Name: Guillaume JAY
Date: 5/5/2008 3:54:57 PM
Comment:
I changed the end to (?<addend>\d*))? (added * after d) because 14D10+86 is a valid dice expression


Title: Minor correction
Name: Guillaume JAY
Date: 5/5/2008 3:54:42 PM
Comment:
I changed the end to (?<addend>\d*))? (added * after d) because 14D10+86 is a valid dice expression


Title: Edit
Name: Janine White
Date: 7/19/2004 10:39:32 AM
Comment:
Thanks for the suggestion. I have updated the regex.


Title: Suggestion
Name: Bryan Kilian
Date: 7/18/2004 2:47:48 PM
Comment:
Only thing I would suggest is replacing the * at the end with a ? (match 0 or 1 times). Your current regex will match 3d6+1+2+3


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials