Regular Expressions (RegEx) are algorithms that can be used to machine grade short answer, fill in the blank, arithmetic, and significant figures questions. Learn how to create your own Regular Expressions at Compose: Create Your Own Regular Expressions. For help using a tool that produces Regular Expressions for you, see Generate: Use the RegEx Generator.
Note: Use of RegEx in D2L quizzes may require spot-checking and/or manual regrading. Please review the materials provided to determine if RegEx is a good fit for your course.
1. Compose: Create Your Own Regular Expressions
Review examples to learn common RegEx commands and their functions.
Detailed information and interactive exercises can be found in this self-paced tutorial.
Example 1: Case Insensitive Command (?i)
Question: Natural carmine dye is made from the _________ insect.
Accepted answer/s: Cochineal, cochineal, CoChInEaL
Example 2: Either Or Command | (Pipe)
Question: What sound does a cat make?
Accepted answer/s: Meow, Purr, or Hiss
Example 3: Replace any literal character . (Period)
Question: What three-letter "spooky" animal is associated with Halloween?
Accepted answer/s: Bat, Cat, or Rat
Example 4: Define the Beginning and End of a Pattern ^ (Caret) and $ (Dollar)
Note: RegEx commands are greedy and will match any portion of a pattern, unless otherwise specified. For example, yes matches any answer with the word "yes" in it, e.g., yes, yes please, and my answer is yes.
Question: Magnetic resonance imaging is abbreviated as ______.
Accepted answer: MRI - only "MRI" with no additional characters or spaces would be scored correct.
Common Regular Expressions
Matches the preceding character zero or more times.
|cat* matches ca, cat, or catttt|
|\||Backslash||Marks a metacharacter as literal.||
c\.t matches c.t but not cat
|^||Caret||Starts the input string or pattern.||
^cat matches cat, catnip, but not tomcat
|$||Dollar||Ends the input string or pattern.||
cat$ matches cat, tomcat, but not catnip. ^cat$ matches only cat
|(?i)||NA||Makes the pattern case insensitive.||
(?i)cat matches CAT, cat, or CaT
Creates a subexpression.
|wild(cat)* matches wild or wildcat|
Matches any literal character.
|.at matches cat, bat, or rat|
Matches either or.
|cat|dog matches cat or dog.|
D2L Brightspace Documentation: Understanding Regular Expressions
2. Generate: Use the RegEx Generator
Open the RegEx Generator and use its templates to produce custom Regular Expressions.
- Multiple Correct Answers: use for multiple answers
- Multiple Separators: use when words in an answer might be separated by spaces, dashes, slashes, or any single character
- Multiple Suffixes: use when answers may have different endings
- Diacritics: use when answers may contain diacritical marks
How to Use the Tool:
RegEx Generator templates appear as tabs in the upper-left corner of the browser window. All of the templates operate similarly. Any specific instructions for usage can be found in the tab, itself.
- Begin by deciding whether accepted answers will be case sensitive. Leave unchecked if answers are to be case insensitive, e.g., Cat and cat are correct.
- Enter correct answer/s. The number of input fields will expand as needed for the Multiple Correct Answers Template.
- As you type correct answer/s, the RegEx will concurrently appear in the designated area, below.
- Check the RegEx in the Test area by entering correct and incorrect answers.
Note: The RegEx Generator is an evolving tool. Check back often for updates and new templates.
3. Apply: Insert Regular Expressions into D2L Quizzes
Format correct answer choices with RegEx to score open-ended questions.
For help getting started with open-ended questions, see Instructor: Create Open-Ended Questions. To learn how to format correct answer choices for RegEx, continue below.
After typing or pasting your question into the Question Text box, scroll to the answer blank.
Note: Answer blanks may appear differently according to the question type.
Type the RegEx into the answer blank or paste the code generated from the RegEx Generator.
For short answer question types, toggle the leading dropdown menu to Regular Expression (pictured). For fill in the blank questions, select the Regular Expression option from the Evaluation column.
Note: You must indicate that the supplied answer is a Regular Expression. If not, D2L will treat the code as the literal, correct answer. Double, triple check that you have selected Regular Expression.