<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ca">
	<id>https://docs.moodle.org/2x/ca/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rezeau</id>
	<title>MoodleDocs - Contribucions de l&amp;#039;usuari [ca]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/2x/ca/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rezeau"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/Especial:Contribucions/Rezeau"/>
	<updated>2026-05-26T22:07:03Z</updated>
	<subtitle>Contribucions de l&amp;#039;usuari</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=104174</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=104174"/>
		<updated>2013-04-25T14:17:37Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Inserting RegExp sub-questions in Cloze type questions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 1.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it&#039;s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    It&#039;s blue, white, red&lt;br /&gt;
    It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 2&#039;&#039;&#039;.====&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
    colours&lt;br /&gt;
    colors&lt;br /&gt;
    they&#039;re colours&lt;br /&gt;
    they&#039;re colors&lt;br /&gt;
    they are colours&lt;br /&gt;
    they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 3.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 4.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
The &#039;permutation&#039; feature (introduced in regexp version &#039;&#039;&#039;2012102900&#039;&#039;&#039; for Moodle 2.3+)&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are the colours of the French flag (in any order)&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;it&#039;s blue, white and red&amp;quot;&lt;br /&gt;
* Answer 2: &amp;lt;nowiki&amp;gt;&amp;quot;it&#039;s [[_blue_, _white_(,| and) _red_]]&amp;quot;.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
it&#039;s (blue, white(,| and) red|blue, red(,| and) white|white, red(,| and) blue|white, blue(,| and) red|red, blue(,| and) white|red, white(,| and) blue) &lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    it&#039;s blue, red, white&lt;br /&gt;
    it&#039;s blue, red and white&lt;br /&gt;
    it&#039;s white, red, blue&lt;br /&gt;
    it&#039;s white, red and blue&lt;br /&gt;
    it&#039;s white, blue, red&lt;br /&gt;
    it&#039;s white, blue and red&lt;br /&gt;
    it&#039;s red, blue, white&lt;br /&gt;
    it&#039;s red, blue and white&lt;br /&gt;
    it&#039;s red, white, blue&lt;br /&gt;
    it&#039;s red, white and blue&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- This &#039;permutation feature&#039; has been asked quite a few times by regexp users. It is definitely &#039;&#039;not&#039;&#039; possible to obtain it by using standard Regular Expressions syntax. &lt;br /&gt;
&lt;br /&gt;
It is possible (but tedious) to write a regular expression including all the possible permutations - as in Answer 2b above - but the &#039;&#039;ad hoc&#039;&#039; syntax I am offering makes it easier to write... provided you strictly adhere to that syntax!&lt;br /&gt;
&lt;br /&gt;
Include within double square brackets the part of the Answer which will contain &#039;permutable&#039; words or phrases. You are actually allowed to have a maximum of 2 such sets of &#039;permutable&#039; words or phrases. But you cannot embed one set within another!&lt;br /&gt;
&lt;br /&gt;
Then, use pairs of underscores (the _ character) to delimit each &#039;permutable&#039; word or phrase. You can still use any of the accepted Regular Expressions characters, as explained here, in your Answers which contain one (or two) such sets of &#039;permutable&#039; words or phrases. If your Answer does not contain an even number of underscores, an Error warning will be displayed upon clicking the Show Alternate Answers button or when trying to Save your question.&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 5.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
Another &#039;permutation&#039; example&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Quote the English proverb that is an encouragement to hard, diligent work.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Answer 1: &amp;quot;Early to bed and early to rise makes an ma healthy, wealthy and wise&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;Early to &amp;lt;nowiki&amp;gt;[[_bed_ and early to _rise_]], makes a man [[_healthy_, _wealthy_ and _wise_]]&amp;lt;/nowiki&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
Early to (bed and early to rise|rise and early to bed) makes a man (healthy, wealthy and wise|healthy, wise and wealthy|wealthy, wise and healthy|wealthy, healthy and wise|wise, healthy and wealthy|wise, wealthy and healthy)&lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wise, wealthy and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wise, wealthy and healthy&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Example question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost (me )?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Answer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window they can display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
Please note that the &#039;&#039;teacher&#039;&#039; will always be able to see that &amp;quot;other accepted answers&amp;quot; section when reviewing the Quiz answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:23 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-24/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-24/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.4 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_24_STABLE...multianswer_regexp-24&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please note...&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
1.- As explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
2.- The syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
3.- The &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
4.- &#039;&#039;&#039;IMPORTANT&#039;&#039;&#039;.- If you would like a more straightforward implementation of REGEXP in the Moodle Cloze/Embedded question type, please vote for  MDL-6371 :: &amp;quot;multianswer qtype cannot use new question types easily&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=104113</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=104113"/>
		<updated>2013-04-22T21:10:17Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* First correct answer */ typo correction&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 1.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it&#039;s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    It&#039;s blue, white, red&lt;br /&gt;
    It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 2&#039;&#039;&#039;.====&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
    colours&lt;br /&gt;
    colors&lt;br /&gt;
    they&#039;re colours&lt;br /&gt;
    they&#039;re colors&lt;br /&gt;
    they are colours&lt;br /&gt;
    they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 3.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 4.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
The &#039;permutation&#039; feature (introduced in regexp version &#039;&#039;&#039;2012102900&#039;&#039;&#039; for Moodle 2.3+)&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are the colours of the French flag (in any order)&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;it&#039;s blue, white and red&amp;quot;&lt;br /&gt;
* Answer 2: &amp;lt;nowiki&amp;gt;&amp;quot;it&#039;s [[_blue_, _white_(,| and) _red_]]&amp;quot;.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
it&#039;s (blue, white(,| and) red|blue, red(,| and) white|white, red(,| and) blue|white, blue(,| and) red|red, blue(,| and) white|red, white(,| and) blue) &lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    it&#039;s blue, red, white&lt;br /&gt;
    it&#039;s blue, red and white&lt;br /&gt;
    it&#039;s white, red, blue&lt;br /&gt;
    it&#039;s white, red and blue&lt;br /&gt;
    it&#039;s white, blue, red&lt;br /&gt;
    it&#039;s white, blue and red&lt;br /&gt;
    it&#039;s red, blue, white&lt;br /&gt;
    it&#039;s red, blue and white&lt;br /&gt;
    it&#039;s red, white, blue&lt;br /&gt;
    it&#039;s red, white and blue&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- This &#039;permutation feature&#039; has been asked quite a few times by regexp users. It is definitely &#039;&#039;not&#039;&#039; possible to obtain it by using standard Regular Expressions syntax. &lt;br /&gt;
&lt;br /&gt;
It is possible (but tedious) to write a regular expression including all the possible permutations - as in Answer 2b above - but the &#039;&#039;ad hoc&#039;&#039; syntax I am offering makes it easier to write... provided you strictly adhere to that syntax!&lt;br /&gt;
&lt;br /&gt;
Include within double square brackets the part of the Answer which will contain &#039;permutable&#039; words or phrases. You are actually allowed to have a maximum of 2 such sets of &#039;permutable&#039; words or phrases. But you cannot embed one set within another!&lt;br /&gt;
&lt;br /&gt;
Then, use pairs of underscores (the _ character) to delimit each &#039;permutable&#039; word or phrase. You can still use any of the accepted Regular Expressions characters, as explained here, in your Answers which contain one (or two) such sets of &#039;permutable&#039; words or phrases. If your Answer does not contain an even number of underscores, an Error warning will be displayed upon clicking the Show Alternate Answers button or when trying to Save your question.&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 5.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
Another &#039;permutation&#039; example&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Quote the English proverb that is an encouragement to hard, diligent work.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Answer 1: &amp;quot;Early to bed and early to rise makes an ma healthy, wealthy and wise&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;Early to &amp;lt;nowiki&amp;gt;[[_bed_ and early to _rise_]], makes a man [[_healthy_, _wealthy_ and _wise_]]&amp;lt;/nowiki&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
Early to (bed and early to rise|rise and early to bed) makes a man (healthy, wealthy and wise|healthy, wise and wealthy|wealthy, wise and healthy|wealthy, healthy and wise|wise, healthy and wealthy|wise, wealthy and healthy)&lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wise, wealthy and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wise, wealthy and healthy&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Example question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost (me )?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Answer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window they can display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
Please note that the &#039;&#039;teacher&#039;&#039; will always be able to see that &amp;quot;other accepted answers&amp;quot; section when reviewing the Quiz answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:23 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=SSL_certificate_for_moodle.org&amp;diff=102620</id>
		<title>SSL certificate for moodle.org</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=SSL_certificate_for_moodle.org&amp;diff=102620"/>
		<updated>2013-01-02T13:13:11Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Provide the CA certificate manually */ correcting certificate&amp;#039;s name and download URL&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Security}}&lt;br /&gt;
== Synopsis ==&lt;br /&gt;
&lt;br /&gt;
When you, as an administrator, [[Notifications|check for available updates]] or [[Automatic updates deployment|install an update]], your Moodle site needs to communicate with moodle.org. This communication is done via the secure HTTPS protocol. Your Moodle site validates the SSL certificate of moodle.org (such as the [https://moodle.org/plugins Moodle plugins directory]) and verifies its identity. To pass this verification, there must be a certificate (in the PEM format) of the [http://en.wikipedia.org/wiki/Certificate_authority certificate authority (CA)] that issued the certificate for moodle.org installed on your server. &lt;br /&gt;
&lt;br /&gt;
The SSL certificate for moodle.org has been issued by the [https://www.digicert.com/digicert-root-certificates.htm DigiCert CA] and signed by their &#039;&#039;DigiCert High Assurance EV Root CA&#039;&#039; certificate.&lt;br /&gt;
&lt;br /&gt;
== Problem ==&lt;br /&gt;
&lt;br /&gt;
If this CA certificate is missing, the remote site (moodle.org) can not be verified and so your Moodle site will refuse to fetch the data (to protect you against so called man-in-the-middle attack). The exact location of the certificate on your server depends on the OS type and other settings. On Linux servers it may be typically found at &#039;&#039;/usr/share/ca-certificates/mozilla/DigiCert_High_Assurance_EV_Root_CA.crt&#039;&#039; for example.&lt;br /&gt;
&lt;br /&gt;
A missing CA certificate results in an error when checking for available updates and attempting to install them.&lt;br /&gt;
&lt;br /&gt;
== Solutions ==&lt;br /&gt;
&lt;br /&gt;
=== Update your operating system (recommended) ===&lt;br /&gt;
&lt;br /&gt;
The recommended way to fix this problem is to update your server&#039;s operating system so that it contains recent SSL certificates from common certificate authorities. For Debian and RedHat based  distributions, these certificates are distributed in the &#039;&#039;ca-certificates&#039;&#039; package.  Gentoo servers provide them via the &#039;&#039;app-misc/ca-certificates&#039;&#039; ebuild. It&#039;s also a good idea to make sure that the OpenSSL libraries (libssl) and cURL libraries (libcurl) are up-to-date on your server.&lt;br /&gt;
&lt;br /&gt;
=== Provide the CA certificate manually ===&lt;br /&gt;
&lt;br /&gt;
If updating the operating system is not an option for you and the administrator of the server refuses to update the CA certificates on the server (despite there being no good reason for not doing so), a possible workaround is to download the &#039;&#039;ca-bundle.crt&#039;&#039; file available at http://curl.haxx.se/ca/cacert.pem - Just &#039;&#039;&#039;rename&#039;&#039;&#039; it to &#039;&#039;moodleorgca.crt&#039;&#039; and place it in the root of your moodledata directory. See MDL-36903.&lt;br /&gt;
&lt;br /&gt;
If the certificate is found there, Moodle will use it instead of relying on the one provided by the operating system.&lt;br /&gt;
&lt;br /&gt;
It must be highlighted that having the CA certificate on your server&#039;s operating system as described above is really the recommended solution. The solution based on moodleorgca.crt should only be considered as a temporary fix.&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=101729</id>
		<title>Embedded Answers (Cloze) question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=101729"/>
		<updated>2012-11-03T17:27:18Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Detailed syntax explanations */ fixed erroneous MULTICHOICE question type description&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
&#039;&#039;&#039;Embedded answers (Cloze)&#039;&#039;&#039; questions consist of a passage of text (in Moodle format) that has various answers embedded within it, including multiple choice, short answers and numerical answers.&lt;br /&gt;
&lt;br /&gt;
There is currently no graphical interface to create these questions - you need to specify the question format using the text box or by importing them from external files. &lt;br /&gt;
&lt;br /&gt;
Lots of people suggest that [[Hot Potatoes]] software is the easiest way to create Embedded answer (Cloze) questions.  Once you have created your questions on your PC, you can then import them into Moodle&#039;s quiz module.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
&lt;br /&gt;
#Select the question category&lt;br /&gt;
#Give the question a descriptive name - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the passage of text (in Moodle format - see [[Embedded_Answers_%28Cloze%29_question_type#Format|Format]] below) into the &#039;question text&#039; field.&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately above the question text.&lt;br /&gt;
#Set the &#039;default question grade&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;Penalty factor&#039; (see [[Embedded_Answers_%28Cloze%29_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#The editor has been modified and allows you to test if your syntax is good. The different questions elements decoded will be displayed and syntax errors pinpoint. However, it cannot check if the question decoded is two questions in one because of an error syntax.&lt;br /&gt;
#Click Save changes to add the question to the category.&lt;br /&gt;
&lt;br /&gt;
=== Penalty factor ===&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; only applies when the question is used in a quiz using adaptive mode - i.e. where the student is allowed multiple attempts at a question even within the same attempt at the quiz. If the penalty factor is more than 0, then the student will lose that proportion of the &#039;&#039;&#039;maximum&#039;&#039;&#039; grade upon each successive attempt. For example, if the default question grade is 10, and the penalty factor is 0.2, then each successive attempt after the first one will incur a penalty of 0.2 x 10 = 2 points.&lt;br /&gt;
&lt;br /&gt;
==Question rendering==&lt;br /&gt;
&lt;br /&gt;
The question answer INPUT HTML ELEMENT ( Short and Numerical) or SELECT HTML ELEMENT (multichoice) are normally displayed in-line with the text.&lt;br /&gt;
&lt;br /&gt;
The size of INPUT HTML ELEMENT ( Short and Numerical) will be adjustable to the length of the longest answer (good or bad) + a random number (0 to 15% total length).([[User:Pierre Pichet|Pierre Pichet]] 15:37, 26 January 2008 (CST))&lt;br /&gt;
&lt;br /&gt;
The size will adjust to the length of the student response when displayed in the grading and feedback process.&lt;br /&gt;
&lt;br /&gt;
The size of the SELECT HTML ELEMENT (multichoice) adjusts itself automatically to the longest answer.&lt;br /&gt;
&lt;br /&gt;
==Format==&lt;br /&gt;
&lt;br /&gt;
Questions consist of a passage of text (in Moodle format) that has various sub-questions embedded within it, including&lt;br /&gt;
&lt;br /&gt;
* short answers (SHORTANSWER or SA or MW), case is unimportant,&lt;br /&gt;
* short answers (SHORTANSWER_C or SAC or MWC), case must match,&lt;br /&gt;
* numerical answers (NUMERICAL or NM),&lt;br /&gt;
* multiple choice (MULTICHOICE or MC), represented as a dropdown menu in-line in the text&lt;br /&gt;
* multiple choice (MULTICHOICE_V or MCV), represented a vertical column of radio buttons, or&lt;br /&gt;
* multiple choice (MULTICHOICE_H or MCH), represented as a horizontal row of radio-buttons.&lt;br /&gt;
&lt;br /&gt;
The structure of  each cloze sub-question is identical:&lt;br /&gt;
:&#039;&#039;&#039;{&#039;&#039;&#039;  start the cloze sub-question with a bracket (AltGr+7)&lt;br /&gt;
:&#039;&#039;&#039;1&#039;&#039;&#039; define a grade for each cloze by  a number (optional). This used for calculation of question grading.&lt;br /&gt;
:&#039;&#039;&#039;:SHORTANSWER:&#039;&#039;&#039; define the type of cloze sub-question. Definition is bounded by &#039;:&#039;. &lt;br /&gt;
:&#039;&#039;&#039;~&#039;&#039;&#039; is a seperator between answer options&lt;br /&gt;
:&#039;&#039;&#039;=&#039;&#039;&#039; marks a correct answer&lt;br /&gt;
:&#039;&#039;&#039;#&#039;&#039;&#039; marks the beginning of an (optional) feedback message&lt;br /&gt;
:&#039;&#039;&#039;}&#039;&#039;&#039;  close the cloze sub-question at the end with a bracket (AltGr+0)&lt;br /&gt;
&lt;br /&gt;
Now a very simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{1:SHORTANSWER:=Berlin} is the capital of Germany.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For full details of the format for embedded-answers questions, see the [[Embedded_Answers_%28Cloze%29_question_type#Detailed_syntax_explanations|detailed syntax explanation]] below.&lt;br /&gt;
&lt;br /&gt;
NB: Be careful when copying a cloze type question into the WYSIWYG HTML editor, as line breaks tend to get added, which destroys the question.&lt;br /&gt;
&lt;br /&gt;
If the correct answer contains } # ~ / &amp;quot; or \ you will have to escape them by putting a \ in front of each such character. The { shouldn&#039;t be escaped, this can be vital in getting TeX expressions to work. In the feedback ~ and } must be escaped otherwise it will be interpreted as &#039;&#039;the next answer&#039;&#039; or &#039;&#039;end of the short answer section&#039;&#039; respectively. Quotation signs: &amp;quot; can lead to trouble anyhow in both places. Use the HTML entity: &amp;amp; quot; (without the space between &#039;&#039;&amp;amp;&#039;&#039; and &#039;&#039;quot;&#039;&#039;). If you want to have Mathematical symbols there can be problems with the \ used in TeX expressions. One alternative can be to use [[unicode]] characters. &lt;br /&gt;
&lt;br /&gt;
See the notes further down about numerical embedded question!&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
&lt;br /&gt;
====Example 1====&lt;br /&gt;
The following text creates a simple embedded-answers question:&lt;br /&gt;
&lt;br /&gt;
 Match the following cities with the correct state:&lt;br /&gt;
 * San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
 * Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
 The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!&lt;br /&gt;
 ~%50%Marseille#No, that is the second largest city in France (after&lt;br /&gt;
 Paris).~*#Wrong answer. The capital of France is Paris, of course.}.&lt;br /&gt;
&lt;br /&gt;
And the result will be:&lt;br /&gt;
 &lt;br /&gt;
[[Image:Cloze.gif|Cloze question type]] &lt;br /&gt;
&lt;br /&gt;
====Example 2====&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: 1em;border: 1px dashed #FFB53A;color: black;background-color: #f9f9f9;font-family: monospace;font-size:1.2em;&amp;quot;&amp;gt;&lt;br /&gt;
This question consists of some text with an answer embedded right here {1:MULTICHOICE:Wrong answer#Feedback for this wrong answer~Another wrong answer#Feedback for the other wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
and right after that you will have to deal with this short answer {1:SHORTANSWER:Wrong answer#Feedback for this wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
and finally we have a floating point number {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8~%50%23.8:2#Feedback for half credit answer in the nearby region of the correct answer}.&lt;br /&gt;
&lt;br /&gt;
The  multichoice question can also be shown in the vertical display of the standard moodle multiple choice.&lt;br /&gt;
{2:MCV:1. Wrong answer#Feedback for this wrong answer~2. Another wrong answer#Feedback for the other wrong answer~=3. Correct answer#Feedback for correct answer~%50%4. Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
Or in an horizontal display that is included here in a table&lt;br /&gt;
{2:MCH:a. Wrong answer#Feedback for this wrong answer~b. Another wrong answer#Feedback for the other wrong answer~=c. Correct answer#Feedback for correct answer~%50%d. Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
A shortanswer question where case must match. Write moodle in upper case letters {1:SHORTANSWER_C:moodle#Feedback for moodle in lower case ~=MOODLE#Feedback for MOODLE in upper case ~%50%Moodle#Feedback for only first letter in upper case}&lt;br /&gt;
&lt;br /&gt;
Note that addresses like www.moodle.org and smileys :-) all work as normal:&lt;br /&gt;
&lt;br /&gt;
a) How good is this? {:MULTICHOICE:=Yes#Correct~No#We have a different opinion}&lt;br /&gt;
&lt;br /&gt;
b) What grade would you give it? {3:NUMERICAL:=3:2}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
[[Image:Cloze example.png]]&lt;br /&gt;
&lt;br /&gt;
Some things to note:&lt;br /&gt;
* The individual embedded answers are represented by the code in braces {}.&lt;br /&gt;
* The number at the start is the &#039;weight&#039;, so in this case each answer contributes an equal share of the overall grade.&lt;br /&gt;
* The correct option in each case is preceded either by an = sign or by %100%. &lt;br /&gt;
* The text appearing after the # that follows each option is the feedback that the student will see if they choose that option.&lt;br /&gt;
* If the student enters &#039;Marseille&#039; in the final example, they score 50% of the total grade.&lt;br /&gt;
* The asterisk * preceding the &amp;quot;Wrong answer&amp;quot; feedback in the final example means that the student will see this feedback if they enter anything other than &amp;quot;Paris&amp;quot; or &amp;quot;Marseille&amp;quot;.&lt;br /&gt;
* For multiple choice vertical or horizontal rendering there is no automatic numbering, though can added at each answer.&lt;br /&gt;
&lt;br /&gt;
==Detailed syntax explanations==&lt;br /&gt;
# all question items within a cloze-type question are coded inside curled braces { }&lt;br /&gt;
# the number which appears between the opening brace and the colon {1: is the weighting of that item; if it is set at 1 for all the items, it needs not be specified, so you can have {:&lt;br /&gt;
# after the colon we have the item question type: MULTICHOICE, SHORTANSWER, NUMERICAL&lt;br /&gt;
# &#039;&#039;&#039;NOTE&#039;&#039;&#039;.- If you have installed the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 REGEXP question type plugin] you can also use the REGEXP question type&lt;br /&gt;
# the syntax for MULTICHOICE and SHORTANSWER is the same; the only difference is in the displaying of the item to the student&lt;br /&gt;
# the order of the various answers is indifferent (except if you want a catch-all for wrong answers, see #13 below)&lt;br /&gt;
# a correct answer is preceded with the equal sign = or a percentage (usually %100%) - &#039;&#039;&#039;Note&#039;&#039;&#039;: [[Talk:Embedded_Answers_(Cloze)_question_type| The equal sign (=) doesn&#039;t seem to work with SHORTANSWER.]]&lt;br /&gt;
# a wrong answer is preceded with nothing or a percentage (usually %0%)&lt;br /&gt;
# you can allocate some points between 0 and 100 to some answers, if you put the appropriate percentage&lt;br /&gt;
# all answers except the first one are separated from one another by the tilde ~ sign&lt;br /&gt;
# answers can be followed by an optional feedback message, preceded with the # sign; if there is no feedback message, the # sign can be present or absent, it does not matter&lt;br /&gt;
# note that the feedback message and (since [[User:Pierre Pichet|Pierre Pichet]] 24 May 2008 )in 1.9 the correct answer are displayed in a small popup window (if and when the correct and or feedback have been declared accessible to the students in the Quiz settings) upon mouse hovering. The popup window has a title &amp;quot;feedback&amp;quot; and you can use HTML tags to format your feedback. In some browsers (For example IE5.5) the form fields can cover part of the feedback windows. It can help to not have the formfields for the answers too close to each other.&lt;br /&gt;
# in the SHORTANSWER type you may want to put a catch-all (wrong) answer in order to send a &amp;quot;wrong, try again&amp;quot; feedback; you can do this by inserting an asterisk &#039;&#039;&#039;*&#039;&#039;&#039; as &#039;&#039;&#039;the very last expected answer&#039;&#039;&#039; in your formula&lt;br /&gt;
# in the MULTICHOICE question type the answers are automatically scrambled&lt;br /&gt;
&lt;br /&gt;
==Numerical Cloze questions==	 &lt;br /&gt;
		 &lt;br /&gt;
From the student perspective, a numerical Cloze question looks just like a short-answer question or &#039;&#039;fill in the blanks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The difference is that numerical answers are allowed to have an accepted error. This allows a continuous range of answers to be set. You can also express your answer in some different numerical formats. 23.4 23,4 (some countries use , as a decimal separator) and 2.34E+1 (meaning 2.34*10^1) would be interpreted as the same.&lt;br /&gt;
&lt;br /&gt;
=== False positives ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; the following examples of false positives do &#039;&#039;&#039;not&#039;&#039;&#039; apply to Moodle 1.8+, where you cannot use percentages or fractions as the answers in a numerical Cloze test; Moodle will generate an error if you try to save such a question. However the following may be relevant for earlier versions of Moodle.&lt;br /&gt;
&lt;br /&gt;
 More examples:	 &lt;br /&gt;
 0.5 accepts .5 0.5 ,5 0,5 0.500 5e-1 5E-1 but not 1/2 50% 	 &lt;br /&gt;
 50% accepts 50% 50.0% 5E1% 50/100 even &#039;&#039;&#039;50/1000 50&#039;&#039;&#039; but not 500/1000 0.5	 &lt;br /&gt;
 1/2 accepts 1/2 &#039;&#039;&#039;1/3 1twenty&#039;&#039;&#039; but not 2/4 0.5 0,5 3/6 50% ½	 &lt;br /&gt;
 ½ accepts ½	 &lt;br /&gt;
 HALF doesn&#039;t even accept HALF (maybe &#039;&#039;&#039;0&#039;&#039;&#039;?)	 &lt;br /&gt;
&lt;br /&gt;
If you want to accept several variants you can have them in the same {} but &#039;&#039;&#039;be careful, notice the &amp;quot;false positives&amp;quot; in bold&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
===Syntax for numerical Cloze questions===&lt;br /&gt;
&lt;br /&gt;
The format of a NUMERICAL Cloze question is similar to that of the other Cloze types and they can be mixed in the same question. As with other Cloze tests, you write your question or incomplete text, and add the Cloze code at the point where the student is supposed to enter their numerical answer.&lt;br /&gt;
&lt;br /&gt;
An example of the syntax used is shown below:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: &#039;&#039;&#039; It is preferable to write the code in &#039;source code&#039; mode. The WSIWYG editor can insert linebreaks that make the question not function. The linebreak in the example box below is for readability only! A problem with these questions is the readability of the code! :(	&lt;br /&gt;
		 &lt;br /&gt;
 {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8	 &lt;br /&gt;
 ~%50%23.8:2#Feedback for ½credit near correct answer}. 	 &lt;br /&gt;
	 &lt;br /&gt;
In this example:&lt;br /&gt;
* 2: is the question point weight, which means that this question has twice the weight in the final point(s) for this question as other partial answers with weight 1 (or no declared weight - you can start with {: for the default weight 1) in the same question.&lt;br /&gt;
* NUMERICAL: says what kind of question it is. It must be in CAPS. &lt;br /&gt;
* =23.8:0.1 = or %100% means correct if the answer is 23.8 with an accepted error of 0.1, then any number between 23.7 and 23.9 will be accepted as correct. (In the GIFT numerical question one can express an interval like this 13..15 or 14:1 but in Cloze only 14:1 works.)	 &lt;br /&gt;
* #Feedback for correct answer 23.8 is preceded by #&lt;br /&gt;
* ~%50%23.8:2 ~ is the separator for answer alternatives %50% means this answer would get 50% of the score that the more precise answer had gotten. Because the tolerance here is 2, 21.8 to 25.8 would get this point and feedback.&lt;br /&gt;
&lt;br /&gt;
The feedback (which is seen within a popup window when the user hovers over the answer space) is formattable with HTML tags. For example, if you want an exponent, surround it with superscript tags: &amp;amp;lt;sup&amp;amp;gt; &amp;amp;lt;/sup&amp;amp;gt;. You can even include pictures in the feedback popup, but you must clean out all &amp;quot; characters and save while still in source code mode (not WYSIWYG). So, this works in feedback popup:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=Something.gif /&amp;gt;}	 &lt;br /&gt;
but not this:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=&amp;quot;Something.gif&amp;quot; /&amp;gt;}	 &lt;br /&gt;
&lt;br /&gt;
(ALGEBRA and TEX filters don&#039;t work in the feedback popups, but they can be very useful in the question writing for math/science expressions). But you can use [[Unicode]] characters.	 &lt;br /&gt;
&lt;br /&gt;
If you want to give feedback for any answer that didn&#039;t fit the intervals you already have specified feedback for, add some BIG general intervals, like for positive answers (if they aren&#039;t bigger than 20000 you could add:	 &lt;br /&gt;
 ~%0%10000.0001:10000#Feedback for unspecified not_right answers}	 &lt;br /&gt;
This would give feedback for anything from 0.0001 to 20000.0001 (that hadn&#039;t already gotten feedback). I didn&#039;t want to include 0 since that special case as well as negative ought to have specific reactions.	 &lt;br /&gt;
 ~%0%0#Hey! It can&#039;t be zero	 &lt;br /&gt;
 ~%0%-10000.0001:10000#We just want the size here,	 &lt;br /&gt;
 so a negative value is not what we want}			 &lt;br /&gt;
&lt;br /&gt;
Numerical questions could, before version 1.7, also have case-insensitive non-numerical answers. This is useful whenever the answer for a numerical question is something like +inf, -inf, NaN etc.&lt;br /&gt;
==Importing CLOZE questions==&lt;br /&gt;
If you try importing directly as CLOZE this text:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Single line per question! Match the following cities with the correct state:&lt;br /&gt;
* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
&lt;br /&gt;
The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!~%50%Marseille#No, that is the second largest city in France (after Paris).~*#Wrong answer. The capital of France is Paris, of course.}.&lt;br /&gt;
&lt;br /&gt;
23+ 0.8 = {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8 ~%50%23.8:2#Feedback for ½credit near correct answer}. 	 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get all three questions as different parts of &#039;&#039;&#039;ONE question&#039;&#039;&#039;. (NOTE see that there are no linebreaks between the { } !)&lt;br /&gt;
&lt;br /&gt;
Multiple CLOZE questions can be imported using the XML format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;quiz&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 1  --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #1&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[..............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 2 --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #2&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You would put the question text including CLOZE code in the  .......  spaces.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
This information was drawn from:&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36521 Is there a guide to using the cloze format?] forum discussion&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36430&amp;amp;parent=170308 Cloze-type question syntax] forum post&lt;br /&gt;
&lt;br /&gt;
[[fr:Question Cloze à réponses intégrés]]&lt;br /&gt;
[[ja: 穴埋め問題 ( Cloze ) タイプ]]&lt;br /&gt;
[[de:Lückentext-Frage]]&lt;br /&gt;
[[zh:填空題(克漏字)]]&lt;br /&gt;
[[es:Tipo de Pregunta incrustadas (Cloze)]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101601</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101601"/>
		<updated>2012-10-29T22:03:37Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Example 1. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 1.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it&#039;s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    It&#039;s blue, white, red&lt;br /&gt;
    It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 2&#039;&#039;&#039;.====&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
    colours&lt;br /&gt;
    colors&lt;br /&gt;
    they&#039;re colours&lt;br /&gt;
    they&#039;re colors&lt;br /&gt;
    they are colours&lt;br /&gt;
    they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 3.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 4.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
The &#039;permutation&#039; feature (introduced in regexp version &#039;&#039;&#039;2012102900&#039;&#039;&#039; for Moodle 2.3+)&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are the colours of the French flag (in any order)&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;it&#039;s blue, white and red&amp;quot;&lt;br /&gt;
* Answer 2: &amp;lt;nowiki&amp;gt;&amp;quot;it&#039;s [[_blue_, _white_(,| and) _red_]]&amp;quot;.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
it&#039;s (blue, white(,| and) red|blue, red(,| and) white|white, red(,| and) blue|white, blue(,| and) red|red, blue(,| and) white|red, white(,| and) blue) &lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    it&#039;s blue, red, white&lt;br /&gt;
    it&#039;s blue, red and white&lt;br /&gt;
    it&#039;s white, red, blue&lt;br /&gt;
    it&#039;s white, red and blue&lt;br /&gt;
    it&#039;s white, blue, red&lt;br /&gt;
    it&#039;s white, blue and red&lt;br /&gt;
    it&#039;s red, blue, white&lt;br /&gt;
    it&#039;s red, blue and white&lt;br /&gt;
    it&#039;s red, white, blue&lt;br /&gt;
    it&#039;s red, white and blue&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- This &#039;permutation feature&#039; has been asked quite a few times by regexp users. It is definitely &#039;&#039;not&#039;&#039; possible to obtain it by using standard Regular Expressions syntax. &lt;br /&gt;
&lt;br /&gt;
It is possible (but tedious) to write a regular expression including all the possible permutations - as in Answer 2b above - but the &#039;&#039;ad hoc&#039;&#039; syntax I am offering makes it easier to write... provided you strictly adhere to that syntax!&lt;br /&gt;
&lt;br /&gt;
Include within double square brackets the part of the Answer which will contain &#039;permutable&#039; words or phrases. You are actually allowed to have a maximum of 2 such sets of &#039;permutable&#039; words or phrases. But you cannot embed one set within another!&lt;br /&gt;
&lt;br /&gt;
Then, use pairs of underscores (the _ character) to delimit each &#039;permutable&#039; word or phrase. You can still use any of the accepted Regular Expressions characters, as explained here, in your Answers which contain one (or two) such sets of &#039;permutable&#039; words or phrases. If your Answer does not contain an even number of underscores, an Error warning will be displayed upon clicking the Show Alternate Answers button or when trying to Save your question.&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 5.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
Another &#039;permutation&#039; example&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Quote the English proverb that is an encouragement to hard, diligent work.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Answer 1: &amp;quot;Early to bed and early to rise makes an ma healthy, wealthy and wise&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;Early to &amp;lt;nowiki&amp;gt;[[_bed_ and early to _rise_]], makes a man [[_healthy_, _wealthy_ and _wise_]]&amp;lt;/nowiki&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
Early to (bed and early to rise|rise and early to bed) makes a man (healthy, wealthy and wise|healthy, wise and wealthy|wealthy, wise and healthy|wealthy, healthy and wise|wise, healthy and wealthy|wise, wealthy and healthy)&lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wise, wealthy and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wise, wealthy and healthy&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window they can display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
Please note that the &#039;&#039;teacher&#039;&#039; will always be able to see that &amp;quot;other accepted answers&amp;quot; section when reviewing the Quiz answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:23 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101600</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101600"/>
		<updated>2012-10-29T22:02:26Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Correct answer matching a regular expression pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
====&#039;&#039;&#039;Example 1.&#039;&#039;&#039;====&lt;br /&gt;
&lt;br /&gt;
Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it&#039;s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    It&#039;s blue, white, red&lt;br /&gt;
    It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
    colours&lt;br /&gt;
    colors&lt;br /&gt;
    they&#039;re colours&lt;br /&gt;
    they&#039;re colors&lt;br /&gt;
    they are colours&lt;br /&gt;
    they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.&#039;&#039;&#039; The &#039;permutation&#039; feature (introduced in regexp version &#039;&#039;&#039;2012102900&#039;&#039;&#039; for Moodle 2.3+)&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are the colours of the French flag (in any order)&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;it&#039;s blue, white and red&amp;quot;&lt;br /&gt;
* Answer 2: &amp;lt;nowiki&amp;gt;&amp;quot;it&#039;s [[_blue_, _white_(,| and) _red_]]&amp;quot;.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
it&#039;s (blue, white(,| and) red|blue, red(,| and) white|white, red(,| and) blue|white, blue(,| and) red|red, blue(,| and) white|red, white(,| and) blue) &lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    it&#039;s blue, red, white&lt;br /&gt;
    it&#039;s blue, red and white&lt;br /&gt;
    it&#039;s white, red, blue&lt;br /&gt;
    it&#039;s white, red and blue&lt;br /&gt;
    it&#039;s white, blue, red&lt;br /&gt;
    it&#039;s white, blue and red&lt;br /&gt;
    it&#039;s red, blue, white&lt;br /&gt;
    it&#039;s red, blue and white&lt;br /&gt;
    it&#039;s red, white, blue&lt;br /&gt;
    it&#039;s red, white and blue&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- This &#039;permutation feature&#039; has been asked quite a few times by regexp users. It is definitely &#039;&#039;not&#039;&#039; possible to obtain it by using standard Regular Expressions syntax. &lt;br /&gt;
&lt;br /&gt;
It is possible (but tedious) to write a regular expression including all the possible permutations - as in Answer 2b above - but the &#039;&#039;ad hoc&#039;&#039; syntax I am offering makes it easier to write... provided you strictly adhere to that syntax!&lt;br /&gt;
&lt;br /&gt;
Include within double square brackets the part of the Answer which will contain &#039;permutable&#039; words or phrases. You are actually allowed to have a maximum of 2 such sets of &#039;permutable&#039; words or phrases. But you cannot embed one set within another!&lt;br /&gt;
&lt;br /&gt;
Then, use pairs of underscores (the _ character) to delimit each &#039;permutable&#039; word or phrase. You can still use any of the accepted Regular Expressions characters, as explained here, in your Answers which contain one (or two) such sets of &#039;permutable&#039; words or phrases. If your Answer does not contain an even number of underscores, an Error warning will be displayed upon clicking the Show Alternate Answers button or when trying to Save your question.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Another &#039;permutation&#039; example&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Quote the English proverb that is an encouragement to hard, diligent work.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Answer 1: &amp;quot;Early to bed and early to rise makes an ma healthy, wealthy and wise&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;Early to &amp;lt;nowiki&amp;gt;[[_bed_ and early to _rise_]], makes a man [[_healthy_, _wealthy_ and _wise_]]&amp;lt;/nowiki&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
Early to (bed and early to rise|rise and early to bed) makes a man (healthy, wealthy and wise|healthy, wise and wealthy|wealthy, wise and healthy|wealthy, healthy and wise|wise, healthy and wealthy|wise, wealthy and healthy)&lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wise, wealthy and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wise, wealthy and healthy&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window they can display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
Please note that the &#039;&#039;teacher&#039;&#039; will always be able to see that &amp;quot;other accepted answers&amp;quot; section when reviewing the Quiz answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:23 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101599</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101599"/>
		<updated>2012-10-29T18:25:44Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Display right answers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it&#039;s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    It&#039;s blue, white, red&lt;br /&gt;
    It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
    colours&lt;br /&gt;
    colors&lt;br /&gt;
    they&#039;re colours&lt;br /&gt;
    they&#039;re colors&lt;br /&gt;
    they are colours&lt;br /&gt;
    they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.&#039;&#039;&#039; The &#039;permutation&#039; feature (introduced in regexp version &#039;&#039;&#039;2012102900&#039;&#039;&#039; for Moodle 2.3+)&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are the colours of the French flag (in any order)&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;it&#039;s blue, white and red&amp;quot;&lt;br /&gt;
* Answer 2: &amp;lt;nowiki&amp;gt;&amp;quot;it&#039;s [[_blue_, _white_(,| and) _red_]]&amp;quot;.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
it&#039;s (blue, white(,| and) red|blue, red(,| and) white|white, red(,| and) blue|white, blue(,| and) red|red, blue(,| and) white|red, white(,| and) blue) &lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    it&#039;s blue, red, white&lt;br /&gt;
    it&#039;s blue, red and white&lt;br /&gt;
    it&#039;s white, red, blue&lt;br /&gt;
    it&#039;s white, red and blue&lt;br /&gt;
    it&#039;s white, blue, red&lt;br /&gt;
    it&#039;s white, blue and red&lt;br /&gt;
    it&#039;s red, blue, white&lt;br /&gt;
    it&#039;s red, blue and white&lt;br /&gt;
    it&#039;s red, white, blue&lt;br /&gt;
    it&#039;s red, white and blue&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- This &#039;permutation feature&#039; has been asked quite a few times by regexp users. It is definitely &#039;&#039;not&#039;&#039; possible to obtain it by using standard Regular Expressions syntax. &lt;br /&gt;
&lt;br /&gt;
It is possible (but tedious) to write a regular expression including all the possible permutations - as in Answer 2b above - but the &#039;&#039;ad hoc&#039;&#039; syntax I am offering makes it easier to write... provided you strictly adhere to that syntax!&lt;br /&gt;
&lt;br /&gt;
Include within double square brackets the part of the Answer which will contain &#039;permutable&#039; words or phrases. You are actually allowed to have a maximum of 2 such sets of &#039;permutable&#039; words or phrases. But you cannot embed one set within another!&lt;br /&gt;
&lt;br /&gt;
Then, use pairs of underscores (the _ character) to delimit each &#039;permutable&#039; word or phrase. You can still use any of the accepted Regular Expressions characters, as explained here, in your Answers which contain one (or two) such sets of &#039;permutable&#039; words or phrases. If your Answer does not contain an even number of underscores, an Error warning will be displayed upon clicking the Show Alternate Answers button or when trying to Save your question.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Another &#039;permutation&#039; example&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Quote the English proverb that is an encouragement to hard, diligent work.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Answer 1: &amp;quot;Early to bed and early to rise makes an ma healthy, wealthy and wise&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;Early to &amp;lt;nowiki&amp;gt;[[_bed_ and early to _rise_]], makes a man [[_healthy_, _wealthy_ and _wise_]]&amp;lt;/nowiki&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
Early to (bed and early to rise|rise and early to bed) makes a man (healthy, wealthy and wise|healthy, wise and wealthy|wealthy, wise and healthy|wealthy, healthy and wise|wise, healthy and wealthy|wise, wealthy and healthy)&lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wise, wealthy and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wise, wealthy and healthy&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window they can display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
Please note that the &#039;&#039;teacher&#039;&#039; will always be able to see that &amp;quot;other accepted answers&amp;quot; section when reviewing the Quiz answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:23 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Fitxer:23_correct_responses.jpg&amp;diff=101598</id>
		<title>Fitxer:23 correct responses.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Fitxer:23_correct_responses.jpg&amp;diff=101598"/>
		<updated>2012-10-29T18:23:11Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101597</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101597"/>
		<updated>2012-10-29T18:13:03Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Automatic formatted extra feedback */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it&#039;s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    It&#039;s blue, white, red&lt;br /&gt;
    It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
    colours&lt;br /&gt;
    colors&lt;br /&gt;
    they&#039;re colours&lt;br /&gt;
    they&#039;re colors&lt;br /&gt;
    they are colours&lt;br /&gt;
    they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.&#039;&#039;&#039; The &#039;permutation&#039; feature (introduced in regexp version &#039;&#039;&#039;2012102900&#039;&#039;&#039; for Moodle 2.3+)&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are the colours of the French flag (in any order)&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;it&#039;s blue, white and red&amp;quot;&lt;br /&gt;
* Answer 2: &amp;lt;nowiki&amp;gt;&amp;quot;it&#039;s [[_blue_, _white_(,| and) _red_]]&amp;quot;.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
it&#039;s (blue, white(,| and) red|blue, red(,| and) white|white, red(,| and) blue|white, blue(,| and) red|red, blue(,| and) white|red, white(,| and) blue) &lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    it&#039;s blue, red, white&lt;br /&gt;
    it&#039;s blue, red and white&lt;br /&gt;
    it&#039;s white, red, blue&lt;br /&gt;
    it&#039;s white, red and blue&lt;br /&gt;
    it&#039;s white, blue, red&lt;br /&gt;
    it&#039;s white, blue and red&lt;br /&gt;
    it&#039;s red, blue, white&lt;br /&gt;
    it&#039;s red, blue and white&lt;br /&gt;
    it&#039;s red, white, blue&lt;br /&gt;
    it&#039;s red, white and blue&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- This &#039;permutation feature&#039; has been asked quite a few times by regexp users. It is definitely &#039;&#039;not&#039;&#039; possible to obtain it by using standard Regular Expressions syntax. &lt;br /&gt;
&lt;br /&gt;
It is possible (but tedious) to write a regular expression including all the possible permutations - as in Answer 2b above - but the &#039;&#039;ad hoc&#039;&#039; syntax I am offering makes it easier to write... provided you strictly adhere to that syntax!&lt;br /&gt;
&lt;br /&gt;
Include within double square brackets the part of the Answer which will contain &#039;permutable&#039; words or phrases. You are actually allowed to have a maximum of 2 such sets of &#039;permutable&#039; words or phrases. But you cannot embed one set within another!&lt;br /&gt;
&lt;br /&gt;
Then, use pairs of underscores (the _ character) to delimit each &#039;permutable&#039; word or phrase. You can still use any of the accepted Regular Expressions characters, as explained here, in your Answers which contain one (or two) such sets of &#039;permutable&#039; words or phrases. If your Answer does not contain an even number of underscores, an Error warning will be displayed upon clicking the Show Alternate Answers button or when trying to Save your question.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Another &#039;permutation&#039; example&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Quote the English proverb that is an encouragement to hard, diligent work.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Answer 1: &amp;quot;Early to bed and early to rise makes an ma healthy, wealthy and wise&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;Early to &amp;lt;nowiki&amp;gt;[[_bed_ and early to _rise_]], makes a man [[_healthy_, _wealthy_ and _wise_]]&amp;lt;/nowiki&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
Early to (bed and early to rise|rise and early to bed) makes a man (healthy, wealthy and wise|healthy, wise and wealthy|wealthy, wise and healthy|wealthy, healthy and wise|wise, healthy and wealthy|wise, wealthy and healthy)&lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wise, wealthy and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wise, wealthy and healthy&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window they can display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
[[Image:21 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101595</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101595"/>
		<updated>2012-10-29T18:12:30Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Previewing questions in popup window (teacher only) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it&#039;s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    It&#039;s blue, white, red&lt;br /&gt;
    It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
    colours&lt;br /&gt;
    colors&lt;br /&gt;
    they&#039;re colours&lt;br /&gt;
    they&#039;re colors&lt;br /&gt;
    they are colours&lt;br /&gt;
    they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.&#039;&#039;&#039; The &#039;permutation&#039; feature (introduced in regexp version &#039;&#039;&#039;2012102900&#039;&#039;&#039; for Moodle 2.3+)&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are the colours of the French flag (in any order)&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;it&#039;s blue, white and red&amp;quot;&lt;br /&gt;
* Answer 2: &amp;lt;nowiki&amp;gt;&amp;quot;it&#039;s [[_blue_, _white_(,| and) _red_]]&amp;quot;.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
it&#039;s (blue, white(,| and) red|blue, red(,| and) white|white, red(,| and) blue|white, blue(,| and) red|red, blue(,| and) white|red, white(,| and) blue) &lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    it&#039;s blue, red, white&lt;br /&gt;
    it&#039;s blue, red and white&lt;br /&gt;
    it&#039;s white, red, blue&lt;br /&gt;
    it&#039;s white, red and blue&lt;br /&gt;
    it&#039;s white, blue, red&lt;br /&gt;
    it&#039;s white, blue and red&lt;br /&gt;
    it&#039;s red, blue, white&lt;br /&gt;
    it&#039;s red, blue and white&lt;br /&gt;
    it&#039;s red, white, blue&lt;br /&gt;
    it&#039;s red, white and blue&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- This &#039;permutation feature&#039; has been asked quite a few times by regexp users. It is definitely &#039;&#039;not&#039;&#039; possible to obtain it by using standard Regular Expressions syntax. &lt;br /&gt;
&lt;br /&gt;
It is possible (but tedious) to write a regular expression including all the possible permutations - as in Answer 2b above - but the &#039;&#039;ad hoc&#039;&#039; syntax I am offering makes it easier to write... provided you strictly adhere to that syntax!&lt;br /&gt;
&lt;br /&gt;
Include within double square brackets the part of the Answer which will contain &#039;permutable&#039; words or phrases. You are actually allowed to have a maximum of 2 such sets of &#039;permutable&#039; words or phrases. But you cannot embed one set within another!&lt;br /&gt;
&lt;br /&gt;
Then, use pairs of underscores (the _ character) to delimit each &#039;permutable&#039; word or phrase. You can still use any of the accepted Regular Expressions characters, as explained here, in your Answers which contain one (or two) such sets of &#039;permutable&#039; words or phrases. If your Answer does not contain an even number of underscores, an Error warning will be displayed upon clicking the Show Alternate Answers button or when trying to Save your question.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Another &#039;permutation&#039; example&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Quote the English proverb that is an encouragement to hard, diligent work.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Answer 1: &amp;quot;Early to bed and early to rise makes an ma healthy, wealthy and wise&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;Early to &amp;lt;nowiki&amp;gt;[[_bed_ and early to _rise_]], makes a man [[_healthy_, _wealthy_ and _wise_]]&amp;lt;/nowiki&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
Early to (bed and early to rise|rise and early to bed) makes a man (healthy, wealthy and wise|healthy, wise and wealthy|wealthy, wise and healthy|wealthy, healthy and wise|wise, healthy and wealthy|wise, wealthy and healthy)&lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wise, wealthy and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wise, wealthy and healthy&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window they can display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that in Moodle 2.1 (and later versions) the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
[[Image:21 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Fitxer:alternate_answers.jpg&amp;diff=101594</id>
		<title>Fitxer:alternate answers.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Fitxer:alternate_answers.jpg&amp;diff=101594"/>
		<updated>2012-10-29T18:11:09Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: uploaded a new version of &amp;amp;quot;File:alternate answers.jpg&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101593</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101593"/>
		<updated>2012-10-29T18:03:51Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Correct answer matching a regular expression pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it&#039;s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    It&#039;s blue, white, red&lt;br /&gt;
    It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
    colours&lt;br /&gt;
    colors&lt;br /&gt;
    they&#039;re colours&lt;br /&gt;
    they&#039;re colors&lt;br /&gt;
    they are colours&lt;br /&gt;
    they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.&#039;&#039;&#039; The &#039;permutation&#039; feature (introduced in regexp version &#039;&#039;&#039;2012102900&#039;&#039;&#039; for Moodle 2.3+)&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are the colours of the French flag (in any order)&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;it&#039;s blue, white and red&amp;quot;&lt;br /&gt;
* Answer 2: &amp;lt;nowiki&amp;gt;&amp;quot;it&#039;s [[_blue_, _white_(,| and) _red_]]&amp;quot;.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
it&#039;s (blue, white(,| and) red|blue, red(,| and) white|white, red(,| and) blue|white, blue(,| and) red|red, blue(,| and) white|red, white(,| and) blue) &lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    it&#039;s blue, red, white&lt;br /&gt;
    it&#039;s blue, red and white&lt;br /&gt;
    it&#039;s white, red, blue&lt;br /&gt;
    it&#039;s white, red and blue&lt;br /&gt;
    it&#039;s white, blue, red&lt;br /&gt;
    it&#039;s white, blue and red&lt;br /&gt;
    it&#039;s red, blue, white&lt;br /&gt;
    it&#039;s red, blue and white&lt;br /&gt;
    it&#039;s red, white, blue&lt;br /&gt;
    it&#039;s red, white and blue&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- This &#039;permutation feature&#039; has been asked quite a few times by regexp users. It is definitely &#039;&#039;not&#039;&#039; possible to obtain it by using standard Regular Expressions syntax. &lt;br /&gt;
&lt;br /&gt;
It is possible (but tedious) to write a regular expression including all the possible permutations - as in Answer 2b above - but the &#039;&#039;ad hoc&#039;&#039; syntax I am offering makes it easier to write... provided you strictly adhere to that syntax!&lt;br /&gt;
&lt;br /&gt;
Include within double square brackets the part of the Answer which will contain &#039;permutable&#039; words or phrases. You are actually allowed to have a maximum of 2 such sets of &#039;permutable&#039; words or phrases. But you cannot embed one set within another!&lt;br /&gt;
&lt;br /&gt;
Then, use pairs of underscores (the _ character) to delimit each &#039;permutable&#039; word or phrase. You can still use any of the accepted Regular Expressions characters, as explained here, in your Answers which contain one (or two) such sets of &#039;permutable&#039; words or phrases. If your Answer does not contain an even number of underscores, an Error warning will be displayed upon clicking the Show Alternate Answers button or when trying to Save your question.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Another &#039;permutation&#039; example&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;Quote the English proverb that is an encouragement to hard, diligent work.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Answer 1: &amp;quot;Early to bed and early to rise makes an ma healthy, wealthy and wise&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;Early to &amp;lt;nowiki&amp;gt;[[_bed_ and early to _rise_]], makes a man [[_healthy_, _wealthy_ and _wise_]]&amp;lt;/nowiki&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
Early to (bed and early to rise|rise and early to bed) makes a man (healthy, wealthy and wise|healthy, wise and wealthy|wealthy, wise and healthy|wealthy, healthy and wise|wise, healthy and wealthy|wise, wealthy and healthy)&lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to bed and early to rise makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to bed and early to rise makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to bed and early to rise makes a man wise, wealthy and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wealthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man healthy, wise and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, wise and healthy&lt;br /&gt;
    Early to rise and early to bed makes a man wealthy, healthy and wise&lt;br /&gt;
    Early to rise and early to bed makes a man wise, healthy and wealthy&lt;br /&gt;
    Early to rise and early to bed makes a man wise, wealthy and healthy&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that in Moodle 2.1 (and later versions) the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
[[Image:21 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101583</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101583"/>
		<updated>2012-10-29T17:27:16Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Correct answer matching a regular expression pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it&#039;s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    It&#039;s blue, white, red&lt;br /&gt;
    It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
    colours&lt;br /&gt;
    colors&lt;br /&gt;
    they&#039;re colours&lt;br /&gt;
    they&#039;re colors&lt;br /&gt;
    they are colours&lt;br /&gt;
    they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.&#039;&#039;&#039; The &#039;permutation&#039; feature (introduced in regexp version &#039;&#039;&#039;2012102900&#039;&#039;&#039; for Moodle 2.3+)&lt;br /&gt;
&lt;br /&gt;
Question: &amp;quot;What are the colours of the French flag (in any order)&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;it&#039;s blue, white and red&amp;quot;&lt;br /&gt;
* Answer 2: &amp;lt;nowiki&amp;gt;&amp;quot;it&#039;s [[_blue_, _white_(,| and) _red_]]&amp;quot;.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:&lt;br /&gt;
&lt;br /&gt;
it&#039;s (blue, white(,| and) red|blue, red(,| and) white|white, red(,| and) blue|white, blue(,| and) red|red, blue(,| and) white|red, white(,| and) blue) &lt;br /&gt;
&lt;br /&gt;
and it will match all the following answers:&lt;br /&gt;
    it&#039;s blue, white, red&lt;br /&gt;
    it&#039;s blue, white and red&lt;br /&gt;
    it&#039;s blue, red, white&lt;br /&gt;
    it&#039;s blue, red and white&lt;br /&gt;
    it&#039;s white, red, blue&lt;br /&gt;
    it&#039;s white, red and blue&lt;br /&gt;
    it&#039;s white, blue, red&lt;br /&gt;
    it&#039;s white, blue and red&lt;br /&gt;
    it&#039;s red, blue, white&lt;br /&gt;
    it&#039;s red, blue and white&lt;br /&gt;
    it&#039;s red, white, blue&lt;br /&gt;
    it&#039;s red, white and blue&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- This &#039;permutation feature&#039; has been asked quite a few times by regexp users. It is definitely &#039;&#039;not&#039;&#039; possible to obtain it by using standard Regular Expressions syntax. &lt;br /&gt;
&lt;br /&gt;
It is possible (but tedious) to write a regular expression including all the possible permutations - as in Answer 2b above - but the &#039;&#039;ad hoc&#039;&#039; syntax I am offering makes it easier to write... provided you strictly adhere to that syntax!&lt;br /&gt;
&lt;br /&gt;
Include within double square brackets the part of the Answer which will contain &#039;permutable&#039; words or phrases. You are actually allowed to have a maximum of 2 such sets of &#039;permutable&#039; words or phrases. But you cannot embed one set within another!&lt;br /&gt;
&lt;br /&gt;
Then, use pairs of underscores (the _ character) to delimit each &#039;permutable&#039; word or phrase. You can still use any of the accepted Regular Expressions characters, as explained here, in your Answers which contain one (or two) such sets of &#039;permutable&#039; words or phrases. If your Answer does not contain an even number of underscores, an Error warning will be displayed upon clicking the Show Alternate Answers button or when trying to Save your question.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that in Moodle 2.1 (and later versions) the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
[[Image:21 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101286</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=101286"/>
		<updated>2012-10-12T20:30:56Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Correct answer matching a regular expression pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it&#039;s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
** colours&lt;br /&gt;
** colors&lt;br /&gt;
** they&#039;re colours&lt;br /&gt;
** they&#039;re colors&lt;br /&gt;
** they are colours&lt;br /&gt;
** they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that in Moodle 2.1 (and later versions) the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
[[Image:21 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Matching_question_type&amp;diff=100499</id>
		<title>Matching question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Matching_question_type&amp;diff=100499"/>
		<updated>2012-09-14T13:18:06Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Question set-up in Question bank */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
Matching questions have a content area and a list of names or statements which must be correctly matched against another list of names or statements. For example &amp;quot;Match the Capital with the Country&amp;quot; with the two lists &amp;quot;Canada, Italy, Japan&amp;quot; and &amp;quot;Ottawa, Rome, Tokyo&amp;quot;. In the Quiz Module, each match is equally weighted to contribute towards the grade for the total question.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Question set-up in Question bank==&lt;br /&gt;
&lt;br /&gt;
#Select the question category&lt;br /&gt;
#Give the question a descriptive name - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter some instructions in the &#039;Question text&#039; field to tell the students what they are matching.&lt;br /&gt;
#Set the &#039;Default mark&#039; (i.e. the maximum number of points for this question).&lt;br /&gt;
#If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Check the &#039;shuffle&#039; box if you want the answers in the drop-down menus to be shuffled. Note: The Quiz display setting must also be set to shuffle within a questions for this to work.&lt;br /&gt;
#For the first matching item, enter the question and a matching answer.&lt;br /&gt;
#Fill in &#039;&#039;at least&#039;&#039; two questions and three answers. You can enter as many as 10 items (or more - [[Matching_question_type#See_also|see &#039;See also&#039; below]]). You can provide extra wrong answers by giving an answer with a blank question.&lt;br /&gt;
#Set the &#039;Penalty for each incorrect try&#039; (see [[Matching_question_type#Grading|grading]] below).&lt;br /&gt;
#Click Save changes to add the question to the category.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
* Each sub-question is equally weighted to contribute towards the grade for the total question.  For example a student who correctly matches 3 of the 4 possible matches will receive 3/4 or 75% of the total possible score for that question.&lt;br /&gt;
* The &#039;penalty factor&#039; only applies when the question is used in a quiz using adaptive mode - i.e. where the student is allowed multiple attempts at a question even within the same attempt at the quiz. If the penalty factor is more than 0, then the student will lose that proportion of the &#039;&#039;&#039;maximum&#039;&#039;&#039; grade upon each successive attempt. For example, if the default question grade is 10, and the penalty factor is 0.2, then each successive attempt after the first one will incur a penalty of 0.2 x 10 = 2 points.&lt;br /&gt;
&lt;br /&gt;
==Repeated entries==&lt;br /&gt;
&lt;br /&gt;
It is possible to have repeated entries in one of the lists but care should be taken to make the repeats identical. For example &amp;quot;Identify the type of these creatures&amp;quot; with the lists &amp;quot;Ant, Cow, Dog, Sparrow&amp;quot; and &amp;quot;Insect, Mammal, Mammal, Bird&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==Ordered questions==&lt;br /&gt;
In the Quiz module, it is possible for both the question list and the answer list to be shuffled. The answer list is always shuffled. The &amp;quot;shuffle within questions&amp;quot; must be &amp;quot;Yes&amp;quot; as a quiz setting under Display AND the shuffle question box must be check on the individual question.&lt;br /&gt;
&lt;br /&gt;
Consider the question &amp;quot;Match the letter with its position in the alphabet&amp;quot; with the question list &amp;quot;1, 2, 3, 4&amp;quot; and answer list &amp;quot;A, B, C, D&amp;quot;. The answer list is always shuffled for each student in the pull down list of the possible matches.  However, only when both the quiz and individual question shuffles are turned on, will the question list be shuffled to something like &amp;quot;2,4,1,3&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==Lesson Module matching questions==&lt;br /&gt;
Matching questions are also used in the Lesson Module.  However, while they look similar to the student, they are different for the teacher.  Quizzes don&#039;t have jumps.   &lt;br /&gt;
&lt;br /&gt;
*In the Lesson Module, all matches must be right for the question to be scored as correct.&lt;br /&gt;
*What is called the question list in a Quiz, does not shuffle in the Lesson Module.  In the earlier example, A, B, C , D will always be in that order and 1,2,3,4 will always be shuffled in the Lesson Module.&lt;br /&gt;
*Lesson Module has an &amp;quot;answer&amp;quot; and a &amp;quot;matching answer&amp;quot; instead of a &amp;quot;question&amp;quot; and &amp;quot;answer&amp;quot;.&lt;br /&gt;
*In Lesson Module there has to be matching pairs.  It is not possible to have 4 items in one list to match with 1 of 5 items in another list.  Both lists will be equal in their number.&lt;br /&gt;
&lt;br /&gt;
===Ordered questions in Lesson Module===&lt;br /&gt;
In the Lesson Module, unlike [[Multiple Choice question type|Multiple choice questions]] or the Quiz Module, the question list is always the same order and the choices are shown in a random order.&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks==&lt;br /&gt;
*Matching questions look better on screen if you put the longer piece of text in the question and not the match. For example, when vocabulary matching put the single word in the match and the definition sentence in the question. Otherwise the drop down for long questions will be awkward to use and difficult to read.&lt;br /&gt;
*Matching questions in a Lesson module are slightly different than in a Quiz module when the teacher is in edit mode.  For example, there are scoring differences and a quiz does not use [[Jumps|jumps]].&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=67314 Matching question type: more than 10 items] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[fr:Question d&#039;appariement]]&lt;br /&gt;
[[ca:Tipus_de_pregunta_de_aparellament]]&lt;br /&gt;
[[ja:組み合わせ問題タイプ]]&lt;br /&gt;
[[de:Zuordnungsfragen]]&lt;br /&gt;
[[zh:配合題]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=100372</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=100372"/>
		<updated>2012-09-10T12:07:05Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Inserting RegExp sub-questions in Cloze type questions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
** colours&lt;br /&gt;
** colors&lt;br /&gt;
** they&#039;re colours&lt;br /&gt;
** they&#039;re colors&lt;br /&gt;
** they are colours&lt;br /&gt;
** they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that in Moodle 2.1 (and later versions) the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
[[Image:21 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=99912</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=99912"/>
		<updated>2012-08-09T21:38:00Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* In Accepted Answers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
** colours&lt;br /&gt;
** colors&lt;br /&gt;
** they&#039;re colours&lt;br /&gt;
** they&#039;re colors&lt;br /&gt;
** they are colours&lt;br /&gt;
** they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The question mark (?) can be used either for its RegExp function OR, if escaped, for its &#039;&#039;literal&#039;&#039; value.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4.-&#039;&#039;&#039; &amp;quot;Do you like Jack(ie)?\?&amp;quot; will accept both &amp;quot;Do you like Jack?&amp;quot; and &amp;quot;Do you like Jackie?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that in Moodle 2.1 (and later versions) the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
[[Image:21 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=98948</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=98948"/>
		<updated>2012-06-30T21:38:07Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Inserting RegExp sub-questions in Cloze type questions */ fixed github address for 2.3&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
** colours&lt;br /&gt;
** colors&lt;br /&gt;
** they&#039;re colours&lt;br /&gt;
** they&#039;re colors&lt;br /&gt;
** they are colours&lt;br /&gt;
** they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that in Moodle 2.1 (and later versions) the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
[[Image:21 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-23/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.3 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_23_STABLE...multianswer_regexp-23&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Installation_Quickstart&amp;diff=98923</id>
		<title>Installation Quickstart</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Installation_Quickstart&amp;diff=98923"/>
		<updated>2012-06-28T12:40:31Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: added link to French translation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
&#039;&#039;&#039;This page is intended for administrators who are experienced with installing web server applications and are in a hurry to get up and running. For everybody else, please see [[Installing Moodle]]&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Basic Requirements===&lt;br /&gt;
&lt;br /&gt;
* You will need a working web server (e.g. [[Apache]]), a database (e.g. [[MySQL]] or [[PostgreSQL]]) and have [[PHP]] configured. &lt;br /&gt;
* Moodle requires a number of [[PHP]] extensions. However, Moodle checks early in the installation process and you can fix the problem and re-start the install script if any are missing.&lt;br /&gt;
* If you want Moodle to send email (you probably do) you need a working Sendmail (Unix/Linux) on your server or access to an SMTP mail server.&lt;br /&gt;
&lt;br /&gt;
===Getting Moodle===&lt;br /&gt;
&lt;br /&gt;
You have two basic options:&lt;br /&gt;
* Download your required version from http://moodle.org/downloads ... OR&lt;br /&gt;
* Pull the code from the Git repository (recommended for developers and also makes upgrading very simple):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone -b MOODLE_23_STABLE git://git.moodle.org/moodle.git &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
...this fetches a complete copy of the Moodle repository and then switches to the 2.3 Stable branch.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: only download Moodle from one of the moodle.org sources. Other versions (e.g. control panel based installers, Linux distribution repositories) cannot be guaranteed to work properly, be upgradable or be supportable.&lt;br /&gt;
&lt;br /&gt;
===Create a database===&lt;br /&gt;
&lt;br /&gt;
* Using your chosen database server, create a new empty database. The default encoding must be UTF8. For example, using MySQL:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE DATABASE moodle DEFAULT CHARACTER SET UTF8 COLLATE utf8_unicode_ci;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create a user/password combination with appropriate permissions for the database. For example (MySQL again):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql&amp;gt; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO moodleuser@localhost IDENTIFIED BY &#039;yourpassword&#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create data directory===&lt;br /&gt;
&lt;br /&gt;
* Create an empty directory to hold Moodle files. It &#039;&#039;&#039;must not&#039;&#039;&#039; be in the area served by the web server and must have permissions so that the web server user can write to it. Typically, either make it owned by the web server user or give it write permissions for &#039;everyone&#039;.&lt;br /&gt;
&lt;br /&gt;
===Install Moodle code===&lt;br /&gt;
&lt;br /&gt;
* Unzip / move / copy the Moodle code (obtained above) so that it will be served by your web server (e.g. on Debian based Linux, move to /var/www/moodle)&lt;br /&gt;
* Check the permissions and make sure that the web server does &#039;&#039;&#039;not&#039;&#039;&#039; have permissions to write to any of the files in the Moodle code directories (a very common root cause of sites being hacked).&lt;br /&gt;
* If you need to, configure your web server to serve the Moodle site with your chosen URL.&lt;br /&gt;
&lt;br /&gt;
===Configure Moodle===&lt;br /&gt;
&lt;br /&gt;
* In the Moodle code directory, find the file &#039;&#039;config-dist.php&#039;&#039; and copy it to a new file called &#039;&#039;config.php&#039;&#039; (but read next step, &#039;Install Moodle&#039;, first).&lt;br /&gt;
* Edit config.php with your favourite editor and change the appropriate settings to point to your site, directories and database. &#039;&#039;Note: the Moodle install script will create config.php for you if it does not exist but make sure you (re-)set permissions appropriately afterwards&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Install Moodle===&lt;br /&gt;
&lt;br /&gt;
* Go to the URL for your moodle site in a browser (installation will complete automatically) or run the command line version at (requires cli version of PHP):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/install.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The CLI creates the config.php for you and will not run if you created one in the previous step.&lt;br /&gt;
* After completing the install make sure your file permissions are ok for the Moodle program files (not writeable by web server) and the Moodle data files (writeable by web server).&lt;br /&gt;
&lt;br /&gt;
===Set up cron===&lt;br /&gt;
&lt;br /&gt;
* You will need a cron job to run periodically. A typical Unix cron entry will be as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*/15 * * * *    /usr/bin/php /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See [[Cron]] for more options.&lt;br /&gt;
&lt;br /&gt;
===Congratulations!===&lt;br /&gt;
&lt;br /&gt;
You are now ready to use your Moodle site. If you run into problems see the &#039;See slso&#039; links below.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Installing Moodle]] - A more detailed installation guide&lt;br /&gt;
* [[Installation FAQ]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=28 Installation problems forum]&lt;br /&gt;
&lt;br /&gt;
[[ja:インストールクイックスタート]]&lt;br /&gt;
[[de:Installation in Kürze]]&lt;br /&gt;
[[fr:Installation_rapide]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Course_requester_role&amp;diff=98530</id>
		<title>Course requester role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Course_requester_role&amp;diff=98530"/>
		<updated>2012-06-16T12:57:03Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}The role of Course requester may be used to restrict users who can make [[Course request|course requests]], perhaps to teachers only.&lt;br /&gt;
&lt;br /&gt;
By default, all authenticated users can make course requests. To change this:&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the authenticated user role and change the capability [[Capabilities/moodle/course:request|moodle/course:request]] from allow to not set.&lt;br /&gt;
#Scroll to the bottom (or top) of the page and click the &#039;Save changes&#039; button.&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Course requester, short name and description.&lt;br /&gt;
#Under &amp;quot;Context types where this role may be assigned&amp;quot;, click on the &amp;quot;System&amp;quot; tick box turning it on.&lt;br /&gt;
#Change the capability moodle/course:request to allow.&lt;br /&gt;
#Click the button &amp;quot;Create this role&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: It is necessary to create a new role, rather than simply changing the capability for the teacher role, because it needs to be assigned as a system role. (The role of teacher is generally assigned in the course or course category context.)&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039;.&lt;br /&gt;
#Choose the course requester role to assign.&lt;br /&gt;
#Select one or more users in the Potential users list, and use the left-facing arrow button to add it to the Existing users list. If you want all your institution&#039;s teachers to be able to make course requests, you need to select and add all their names to the Existing users list.&lt;br /&gt;
&lt;br /&gt;
==Add a Course Request block==&lt;br /&gt;
&lt;br /&gt;
Now, this will work fine for those users who already have a Teacher role in at least ONE course on your Moodle site. When they log in, they will see the list of course(s) that they are enrolled in as Teacher(s) plus an All courses button. Clicking on that &#039;&#039;&#039;All courses&#039;&#039;&#039; button will show the complete list of courses on the site, plus a &#039;&#039;&#039;Request a course&#039;&#039;&#039; button, which they will be able to click to request a course.&lt;br /&gt;
&lt;br /&gt;
However, those Moodle site users whom we have assigned to the Course requester role in System &#039;&#039;and who do not yet have a Teacher role in at least ONE course on your Moodle site will not see that &#039;&#039;&#039;All courses&#039;&#039;&#039; button&#039;&#039;, since by default all the available courses will be displayed. And consequently, the &#039;&#039;&#039;Request a course&#039;&#039;&#039; button will not appear to them. To solve this, a further step is required, viz. creating an HTML block on the front page with a direct link to /course/request.php! And of course that block will have to be made invisible to students etc.&lt;br /&gt;
&lt;br /&gt;
# On the front page, Add a block: HTML: title: &#039;&#039;Course request&#039;&#039; contents: &#039;&#039;Click here to request a course&#039;&#039; with a link to &amp;lt;yourmoodlesite&amp;gt;/course/request.php&lt;br /&gt;
&lt;br /&gt;
# Edit that block&#039;s settings: Permissions: View block: Course requester and Teacher. So that only users with a Course requester or Teacher role will be able to view that block; students etc. won&#039;t see it.&lt;br /&gt;
&lt;br /&gt;
Now Course requesters who are not yet enrolled as Teachers in Courses will be able to see that HTML block, click on the link and request a course. Of course, this block is redundant for those Course requesters who are also Teachers, but it is needed for Teachers requesting the creation of &#039;&#039;their very first course&#039;&#039; on the Moodle site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
Forum thread: Only teachers can request courses - how to do that? http://moodle.org/mod/forum/discuss.php?d=195211&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Course_requester_role&amp;diff=98529</id>
		<title>Course requester role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Course_requester_role&amp;diff=98529"/>
		<updated>2012-06-16T12:54:00Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: Added HTML block necessary for 1st request&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}The role of Course requester may be used to restrict users who can make [[Course request|course requests]], perhaps to teachers only.&lt;br /&gt;
&lt;br /&gt;
By default, all authenticated users can make course requests. To change this:&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the authenticated user role and change the capability [[Capabilities/moodle/course:request|moodle/course:request]] from allow to not set.&lt;br /&gt;
#Scroll to the bottom (or top) of the page and click the &#039;Save changes&#039; button.&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Course requester, short name and description.&lt;br /&gt;
#Under &amp;quot;Context types where this role may be assigned&amp;quot;, click on the &amp;quot;System&amp;quot; tick box turning it on.&lt;br /&gt;
#Change the capability moodle/course:request to allow.&lt;br /&gt;
#Click the button &amp;quot;Create this role&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: It is necessary to create a new role, rather than simply changing the capability for the teacher role, because it needs to be assigned as a system role. (The role of teacher is generally assigned in the course or course category context.)&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039;.&lt;br /&gt;
#Choose the course requester role to assign.&lt;br /&gt;
#Select one or more users in the Potential users list, and use the left-facing arrow button to add it to the Existing users list. If you want all your institution&#039;s teachers to be able to make course requests, you need to select and add all their names to the Existing users list.&lt;br /&gt;
&lt;br /&gt;
==Add a &amp;quot;Course Request&amp;quot; block==&lt;br /&gt;
&lt;br /&gt;
Now, this will work fine for those users who already have a Teacher role in at least ONE course on your Moodle site. When they log in, they will see the list of course(s) that they are enrolled in as Teacher(s) plus an All courses button. Clicking on that &#039;&#039;&#039;All courses&#039;&#039;&#039; button will show the complete list of courses on the site, plus a &#039;&#039;&#039;Request a course&#039;&#039;&#039; button, which they will be able to click to request a course.&lt;br /&gt;
&lt;br /&gt;
However, those Moodle site users whom we have assigned to the Course requester role in System &#039;&#039;and who do not yet have a Teacher role in at least ONE course on your Moodle site will not see that &#039;&#039;&#039;All courses&#039;&#039;&#039; button&#039;&#039;, since by default all the available courses will be displayed. And consequently, the &#039;&#039;&#039;Request a course&#039;&#039;&#039; button will not appear to them. To solve this, a further step is required, viz. creating an HTML block on the front page with a direct link to /course/request.php! And of course that block will have to be made invisible to students etc.&lt;br /&gt;
&lt;br /&gt;
# On the front page, Add a block: HTML: title: &#039;&#039;Course request&#039;&#039; contents: &#039;&#039;Click here to request a course&#039;&#039; with a link to &amp;lt;yourmoodlesite&amp;gt;/course/request.php&lt;br /&gt;
&lt;br /&gt;
# Edit that block&#039;s settings: Permissions: View block: Course requester and Teacher. So that only users with a Course requester or Teacher role will be able to view that block; students etc. won&#039;t see it.&lt;br /&gt;
&lt;br /&gt;
Now Course requesters who are not yet enrolled as Teachers in Courses will be able to see that HTML block, click on the link and request a course. Of course, this block is redundant for those Course requesters who are also Teachers, but it is needed for Teachers requesting the creation of &#039;&#039;their very first course&#039;&#039; on the Moodle site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
Forum thread: Only teachers can request courses - how to do that? http://moodle.org/mod/forum/discuss.php?d=195211&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Course_requester_role&amp;diff=98528</id>
		<title>Course requester role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Course_requester_role&amp;diff=98528"/>
		<updated>2012-06-16T12:31:37Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Role assignment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}The role of Course requester may be used to restrict users who can make [[Course request|course requests]], perhaps to teachers only.&lt;br /&gt;
&lt;br /&gt;
By default, all authenticated users can make course requests. To change this:&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the authenticated user role and change the capability [[Capabilities/moodle/course:request|moodle/course:request]] from allow to not set.&lt;br /&gt;
#Scroll to the bottom (or top) of the page and click the &#039;Save changes&#039; button.&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Course requester, short name and description.&lt;br /&gt;
#Under &amp;quot;Context types where this role may be assigned&amp;quot;, click on the &amp;quot;System&amp;quot; tick box turning it on.&lt;br /&gt;
#Change the capability moodle/course:request to allow.&lt;br /&gt;
#Click the button &amp;quot;Create this role&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: It is necessary to create a new role, rather than simply changing the capability for the teacher role, because it needs to be assigned as a system role. (The role of teacher is generally assigned in the course or course category context.)&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039;.&lt;br /&gt;
#Choose the course requester role to assign.&lt;br /&gt;
#Select one or more users in the Potential users list, and use the left-facing arrow button to add it to the Existing users list. If you want all your institution&#039;s teachers to be able to make course requests, you need to select and add all their names to the Existing users list.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
Forum thread: Only teachers can request courses - how to do that? http://moodle.org/mod/forum/discuss.php?d=195211&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Course_requester_role&amp;diff=98527</id>
		<title>Course requester role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Course_requester_role&amp;diff=98527"/>
		<updated>2012-06-16T12:29:20Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Role set-up */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}The role of Course requester may be used to restrict users who can make [[Course request|course requests]], perhaps to teachers only.&lt;br /&gt;
&lt;br /&gt;
By default, all authenticated users can make course requests. To change this:&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the authenticated user role and change the capability [[Capabilities/moodle/course:request|moodle/course:request]] from allow to not set.&lt;br /&gt;
#Scroll to the bottom (or top) of the page and click the &#039;Save changes&#039; button.&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Course requester, short name and description.&lt;br /&gt;
#Under &amp;quot;Context types where this role may be assigned&amp;quot;, click on the &amp;quot;System&amp;quot; tick box turning it on.&lt;br /&gt;
#Change the capability moodle/course:request to allow.&lt;br /&gt;
#Click the button &amp;quot;Create this role&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: It is necessary to create a new role, rather than simply changing the capability for the teacher role, because it needs to be assigned as a system role. (The role of teacher is generally assigned in the course or course category context.)&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039;.&lt;br /&gt;
#Choose the course requester role to assign.&lt;br /&gt;
#Select a user in the potential users list, and use the left-facing arrow button to add it to the existing users list. If you want all teachers to be able to make course requests, you need to select all their names.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
Forum thread: Only teachers can request courses - how to do that? http://moodle.org/mod/forum/discuss.php?d=195211&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Course_requester_role&amp;diff=98526</id>
		<title>Course requester role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Course_requester_role&amp;diff=98526"/>
		<updated>2012-06-16T12:27:10Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}The role of Course requester may be used to restrict users who can make [[Course request|course requests]], perhaps to teachers only.&lt;br /&gt;
&lt;br /&gt;
By default, all authenticated users can make course requests. To change this:&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the authenticated user role and change the capability [[Capabilities/moodle/course:request|moodle/course:request]] from allow to not set.&lt;br /&gt;
#Scroll to the bottom (or top) of the page and click the &#039;Save changes&#039; button.&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Course requester, short name and description.&lt;br /&gt;
#Under &amp;quot;Context types where this role may be assigned&amp;quot;, click on the &amp;quot;System&amp;quot; tick box turning it on.&lt;br /&gt;
#Change the capability moodle/course:request to allow.&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: It is necessary to create a new role, rather than simply changing the capability for the teacher role, because it needs to be assigned as a system role. (The role of teacher is generally assigned in the course or course category context.)&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039;.&lt;br /&gt;
#Choose the course requester role to assign.&lt;br /&gt;
#Select a user in the potential users list, and use the left-facing arrow button to add it to the existing users list. If you want all teachers to be able to make course requests, you need to select all their names.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
Forum thread: Only teachers can request courses - how to do that? http://moodle.org/mod/forum/discuss.php?d=195211&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Building_Lesson&amp;diff=97154</id>
		<title>Building Lesson</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Building_Lesson&amp;diff=97154"/>
		<updated>2012-04-25T07:15:27Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: Undo revision 97144 by Ilcantu (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Lesson}}&lt;br /&gt;
This page is about how to strucure a Moodle lesson once you have created it with the [[Lesson settings]]. For information on how best to use a Moodle lesson and how students approach it, see [[Using Lesson]]&lt;br /&gt;
&lt;br /&gt;
==Planning your lesson==&lt;br /&gt;
*A lesson is made up of pages which may have content for the student to read or questions for them to answer. The questions can be created by the teacher or imported. The teacher decides the order in which these pages appear.&lt;br /&gt;
*You need to have a clear idea beforehand of what you want to do with this lesson. Is it to be a graded, linear learning experience? Or an ungraded, non-linear practice session? Will students be able to go back and revisit areas or is it just a once-only opportunity?&lt;br /&gt;
*Even those who are very comfortable working directly online might find it useful to note down on paper the direction they want their lesson pages to go in, rather than having to remember  and visualise the navigation in their head.&lt;br /&gt;
*For hints and ideas about using the Lesson module, look at [[Using Lesson]] and [[Lesson FAQ]]&lt;br /&gt;
&lt;br /&gt;
==Adding content and questions to your lesson==&lt;br /&gt;
*When you have set up your lesson with the [[Lesson settings]],click &amp;quot;Save and display&amp;quot; and you will be taken to the screen in the screenshot below.&lt;br /&gt;
*If you click &amp;quot;Save and return to course&amp;quot; instead, then click the &amp;quot;update&amp;quot; icon next to the lesson on the page and click &amp;quot;edit&amp;quot; in the &#039;&#039;Settings block&amp;gt;Lesson Administration&#039;&#039;&lt;br /&gt;
[[File:lessonbegin.png]]&lt;br /&gt;
&lt;br /&gt;
===Import questions===&lt;br /&gt;
*If you have some questions in the following formats, you can import them to use in your lesson by clicking the Import questions link. For general information about these question types, see [[Import questions]]&lt;br /&gt;
[[File:importquestions.png]]&lt;br /&gt;
&lt;br /&gt;
===Import a powerpoint===&lt;br /&gt;
*Although this setting is available, it really does not work and is not advised. See [[Import PowerPoint]] for alternatives.&lt;br /&gt;
&lt;br /&gt;
===Add a cluster===&lt;br /&gt;
*A cluster is a group of question pages which will be offered randomly to a student as they work through the lesson.It is best if you have made the question pages beforehand and can then decide where to mark the start and end of the cluster. The start is marked by a &amp;quot;cluster&amp;quot; page and the end by an &amp;quot;end of cluster&amp;quot; page. See [[Clusters]] for more information.&lt;br /&gt;
&lt;br /&gt;
===Add a content page===&lt;br /&gt;
*This is a page where a teacher can provide information to move the lesson forward but without requiring the student to answer specific questions. &lt;br /&gt;
*The student sees the page&#039;s title, some information and then one or more buttons at the bottom to select. &lt;br /&gt;
*When the student clicks on a button, they go to the next page but their choice is not scored.&lt;br /&gt;
&lt;br /&gt;
====Title====&lt;br /&gt;
*The title of a content page appears to the student at the top of the page.&lt;br /&gt;
*A teacher will also see the title in the collapsed edit mode when they are working on the Lesson, and they will also be able to choose the title (and hence this page) from the drop down &amp;quot;jump&amp;quot; lists.&lt;br /&gt;
*The title in a content page is also used with the &amp;quot;display left menu&amp;quot; setting.&lt;br /&gt;
&lt;br /&gt;
====Page contents====&lt;br /&gt;
This is where the tacher can add information for the student,making use of the [[Text editor]] and its multimedia features.&lt;br /&gt;
&lt;br /&gt;
====Content====&lt;br /&gt;
*Here the teacher writes the words they want the student to click on to get to the next part of the lesson.&lt;br /&gt;
*These words will appear to the student as a button.&lt;br /&gt;
*The teacher can check the box to have the buttons appear horizontally, or uncheck it for them to appear centred vertically.&lt;br /&gt;
&lt;br /&gt;
====Format====&lt;br /&gt;
There are 4 format types to choose from when editing text in the content description box. If you wish to have the usual rich text editing icons,choose HTML format. (Note - once you have selected an option, you cannot then go back and change your mind!)However, if you DO choose HTML format, be warned that the student will not see the changes (such as bold or different colours) in the button.&lt;br /&gt;
&lt;br /&gt;
[[File:lessoncontentbuttons.png]]&lt;br /&gt;
&lt;br /&gt;
====Number of options available====&lt;br /&gt;
*How many of these you have depends on your choice in  the &#039;&#039;Maximum Number of Answers&#039;&#039; setting in [[Lesson settings]]&lt;br /&gt;
&lt;br /&gt;
==== The Jump====&lt;br /&gt;
*Each Description in a Content page has a Jumps menu. &amp;quot;Jumps&amp;quot; take a student from one page to another.&lt;br /&gt;
*A &amp;quot;relative jump&amp;quot; is &amp;quot;next page&amp;quot; or &amp;quot;end of lesson&amp;quot; whereas an &amp;quot;absolute jump&amp;quot; gives the actual name of a page.&lt;br /&gt;
*The teacher chooses from the dropdown the correct page to send the student to if they click on the button that will be made from this particular description. Any pages created by the teacher will have their titles appear in this dropdown, allowing them to be selected.&lt;br /&gt;
*When a student clicks on a description button, they are sent to the page defined in the Jump associated with the button.&lt;br /&gt;
*See [[Jumps]] for more detailed information.&lt;br /&gt;
&lt;br /&gt;
===Add a question page===&lt;br /&gt;
*From this link you can choose from a variety of question types which will then be added as pages to your lesson:&lt;br /&gt;
[[File:addquestionpage.png]]&lt;br /&gt;
*&#039;&#039;(Note: These question types are not the same as for the [[Quiz]] and are in no way connected with quiz questions.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*The format of question pages is similar to content pages outlined in [[Building_Lesson#Add_a_content_page| Section 2.4]] above. &lt;br /&gt;
A typical question page could include:&lt;br /&gt;
***&#039;&#039;&#039;Title&#039;&#039;&#039; - the name the student sees at the top of the question page.&lt;br /&gt;
***&#039;&#039;&#039;Page contents&#039;&#039;&#039; - the actual question&lt;br /&gt;
***[[File:examplequestion.png]]&lt;br /&gt;
***&#039;&#039;&#039;Answer/Response/Format/Jump/Score&#039;&#039;&#039; as in the screenshot below&lt;br /&gt;
***[[File:exampleanswer.png]]&lt;br /&gt;
&lt;br /&gt;
===Question types===&lt;br /&gt;
====Multichoice====&lt;br /&gt;
*The student is given a question and a list of answers. The answer list will be shuffled every time the question is view by a student. By default they choose one answer but you can check the box &amp;quot;multiple answer&amp;quot; to allow them to choose more than one answer.&lt;br /&gt;
====Essay====&lt;br /&gt;
*Students can write a longer answer as part of the lesson and this can be graded manually by the teacher. If the main purpose of your lesson is for students to write an essay, consider the [[Assignment module]] instead.&lt;br /&gt;
====Matching====&lt;br /&gt;
*This allows you to set up lists which must be matched against other lists, for instance, words, pictures, numebers etc. The student must match all correctly to receive the score.&lt;br /&gt;
====Numerical====&lt;br /&gt;
*This requires a number as an answer. A number within a range may also be accepted as correct.&lt;br /&gt;
====Short answer====&lt;br /&gt;
*A student must provide a single word or short phrase answer. The teacher must anticipate the possible answers and enter them in the Jump dropdown boxes, using ** wild cards if appropriate.&lt;br /&gt;
====True/false====&lt;br /&gt;
*The student is given a sentence and must decide if it is true or false.&lt;br /&gt;
&lt;br /&gt;
==Moving your lesson forward==&lt;br /&gt;
*0nce you have added your first content or question page, you reach the next screen which displays your page title/type/jumps(ie where the responses take the student to) and actions you can take next:&lt;br /&gt;
[[File:lessonactions.png]]&lt;br /&gt;
*The &#039;&#039;&#039;Actions&#039;&#039;&#039; icons allow you to move (if you have more than one),edit, preview or delete your pages.&lt;br /&gt;
*The drop down allows you to create another page of your choice:&lt;br /&gt;
[[File:lessonactionsdropdown.png]]&lt;br /&gt;
&lt;br /&gt;
*Note the different view options:&lt;br /&gt;
&lt;br /&gt;
====Collapsed view====&lt;br /&gt;
*This gives a brief outline of the lesson structure as in the two screenshots above.&lt;br /&gt;
&lt;br /&gt;
====Expanded view====&lt;br /&gt;
*This shows more detail as in the screenshot below:&lt;br /&gt;
[[File:expandedview.png]]&lt;br /&gt;
==Ending your lesson==&lt;br /&gt;
*To bring the lesson to a close, select the &amp;quot;End of Lesson&amp;quot; option from the Jump menu on any relevant pages.&lt;br /&gt;
*The student will then see a generic message as in the next screenshot, with a direction back to the main course page or to view their grades:&lt;br /&gt;
[[File:endoflesson1.png]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Fitxer:21-completedwordhistory.jpg&amp;diff=96377</id>
		<title>Fitxer:21-completedwordhistory.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Fitxer:21-completedwordhistory.jpg&amp;diff=96377"/>
		<updated>2012-03-10T15:05:11Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Fitxer:21-addedwordhistory.jpg&amp;diff=96376</id>
		<title>Fitxer:21-addedwordhistory.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Fitxer:21-addedwordhistory.jpg&amp;diff=96376"/>
		<updated>2012-03-10T15:04:47Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Fitxer:showhidealternateanswers.jpg&amp;diff=96375</id>
		<title>Fitxer:showhidealternateanswers.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Fitxer:showhidealternateanswers.jpg&amp;diff=96375"/>
		<updated>2012-03-10T15:03:45Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Fitxer:settings01.jpg&amp;diff=96374</id>
		<title>Fitxer:settings01.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Fitxer:settings01.jpg&amp;diff=96374"/>
		<updated>2012-03-10T15:03:16Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=96373</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=96373"/>
		<updated>2012-03-10T14:58:57Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: Copied newly edited doc from 2.1 to 2.2&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;&lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for &#039;&#039;analyzing the student&#039;s answers&#039;&#039; with the aim of &#039;&#039;providing more relevant immediate feedback&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* If [[#casesensivity|Case sensivity]] is set to &amp;quot;No&amp;quot;, this will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What are blue, red and yellow?&amp;quot;. &lt;br /&gt;
* Answer 1: &amp;quot;they are colours&amp;quot;. &lt;br /&gt;
* Answer 2: &amp;quot;(|they(&#039;| a)re )colou?rs&amp;quot;. &lt;br /&gt;
* This will match any of those 6 responses:&lt;br /&gt;
** colours&lt;br /&gt;
** colors&lt;br /&gt;
** they&#039;re colours&lt;br /&gt;
** they&#039;re colors&lt;br /&gt;
** they are colours&lt;br /&gt;
** they are colors&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|they(&#039;| a)re )&amp;quot; will match either nothing or &amp;quot;they&#039;re &amp;quot; or &amp;quot;they are &amp;quot;. In &amp;quot;colou?r&amp;quot;, the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Answer 1: &amp;quot;cat&amp;quot;&lt;br /&gt;
* Answer 2: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their RegExp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their RegExp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The validation system also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
This is a powerful feature of the RegExp question type. It will analyse the student&#039;s answer for words that are required for the answer to be correct. There are 2 ways to do this.&lt;br /&gt;
* Use what is called &amp;quot;negative lookahead assertion&amp;quot; in regular expressions syntax: &#039;&#039;&#039;^(?!.*required.*)&#039;&#039;&#039;&lt;br /&gt;
* or use an &#039;&#039;ad hoc&#039;&#039; pseudo-syntax provided in RegExp (an initial double hyphen): &#039;&#039;&#039;--.*required.*&#039;&#039;&#039;.&lt;br /&gt;
In the examples below, we shall be using the &#039;ad hoc&#039; RegExp pseudo-syntax, and sometimes give the &amp;quot;negative lookahead assertion&amp;quot; equivalent for anyone interested.&lt;br /&gt;
&lt;br /&gt;
Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
Actually, this syntax is not sufficient to track the absence of the word &amp;quot;blue&amp;quot; in a student&#039;s answer such as &amp;quot;it&#039;s blueish, white and red&amp;quot;. To make sure that we want to track the absence of &amp;quot;blue&amp;quot; as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a &amp;quot;word boundary&amp;quot;. Hence the new version of our Example 4:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4b. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*\bblue\b.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s blueish, white and red&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:&lt;br /&gt;
* Teacher Answer 2: &#039;&#039;&#039;^(?!&#039;&#039;&#039;.*\blue\b.*&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name consists of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--^[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--^(b|c|r)&amp;quot;.&lt;br /&gt;
* Sample student Response: &amp;quot;dog&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
In regular expressions syntax, the caret ^ stands for &amp;quot;beginning of character string to be matched&amp;quot;, while the dollar sign $ stands for &amp;quot;end of character string&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;^(?!.*(blue|red|white).*)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039;&lt;br /&gt;
Using the &amp;quot;negative lookahead assertion&amp;quot; syntax, Teacher Answer would look like this: &#039;&#039;&#039;(^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Editing a regular expression question===&lt;br /&gt;
&lt;br /&gt;
[[Image:settings01.jpg]]&lt;br /&gt;
&lt;br /&gt;
====Help Button Mode====&lt;br /&gt;
&lt;br /&gt;
Selecting a mode other than &#039;&#039;None&#039;&#039; will display a button to enable the student to get the next letter or word (including the very first letter or word).&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive mode&#039;&#039; the button displayed will say &amp;quot;Buy next letter&amp;quot; or &amp;quot;Buy next word&amp;quot; according to the mode selected by the teacher. For setting the &amp;quot;cost&amp;quot; of buying a letter or word, see the &#039;&#039;Penalty for incorrect tries and Buying a letter or word&#039;&#039; settings further down the Edit form.&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;Adaptive No penalty&#039;&#039; mode the button displayed will say &amp;quot;Get next letter&amp;quot; or &amp;quot;Get next word&amp;quot;&lt;br /&gt;
&lt;br /&gt;
By default the Help button mode value is set at &#039;&#039;&#039;None&#039;&#039;&#039;. The Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039; as it does not make sense to enable the Help button for non-adaptive tests.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
The editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====Show alternate answers to student====&lt;br /&gt;
Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to &#039;&#039;not&#039;&#039; display all those alternative correct answers. The first correct answer will always be displayed, under the label &amp;quot;The best correct answer is:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
====Show/Hide alternate answers====&lt;br /&gt;
&lt;br /&gt;
When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!&lt;br /&gt;
&lt;br /&gt;
On the other hand, it is the recommended way to check that your &amp;quot;correct answers&amp;quot; expressions are correctly written. Here is an example.&lt;br /&gt;
&lt;br /&gt;
Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.&lt;br /&gt;
&lt;br /&gt;
Please note that clicking the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button will perform an analysis of all the regular expressions you entered in the Answers field. If a syntax error is detected at this stage, the alternative correct answers will &#039;&#039;not&#039;&#039; be displayed, and an &#039;&#039;ad hoc&#039;&#039; error message will displayed above the faulty regular expression.&lt;br /&gt;
&lt;br /&gt;
[[Image:showhidealternateanswers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
Please note that in Moodle 2.1 (and later versions) the RegExp question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only RegExp questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
* (line 3) The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* (line 2) The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* (line 1) An extra feedback system is automatically provided, displaying the student&#039;s submitted response, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strike-through.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strike-through&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
Each time a student clicks the &#039;&#039;&#039;Buy/Get next letter/word&#039;&#039;&#039; button to buy/get a letter/word, that letter or word is added to his response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red. &lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter/word was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Image:21-addedwordhistory.jpg]]&lt;br /&gt;
----&lt;br /&gt;
If the student clicked the &#039;&#039;&#039;Buy/Get next word&#039;&#039;&#039; button while his current submitted answer contained the beginning of a (correct) word, the full correct word is displayed in the Answer field, and the feedback message says &amp;quot;&#039;&#039;Completed&#039;&#039; word&amp;quot; rather than &amp;quot;&#039;&#039;Added&#039;&#039; word&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-completedwordhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question&#039;s &#039;&#039;Show alternate answers to student&#039;&#039; setting is set to &#039;&#039;&#039;Yes&#039;&#039;&#039;, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
[[Image:21 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting RegExp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace 2 files (&#039;&#039;renderer.php&#039;&#039; and &#039;&#039;questiontype.php&#039;&#039;) on your &#039;&#039;&amp;lt;yourmoodle&amp;gt;/question/type/multianswer&#039;&#039; with the hacked files available from the links below.&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-22/question/type/multianswer/questiontype.php&lt;br /&gt;
&lt;br /&gt;
https://raw.github.com/rezeau/moodle/multianswer_regexp-22/question/type/multianswer/renderer.php&lt;br /&gt;
&lt;br /&gt;
Note.- If you are interested in comparing the 2 &amp;quot;standard&amp;quot; Moodle 2.2 multianswer files with the &amp;quot;RegExp hacked&amp;quot; files, go to &lt;br /&gt;
&lt;br /&gt;
https://github.com/rezeau/moodle/compare/MOODLE_22_STABLE...multianswer_regexp-22&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting RegExp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a RegExp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
-------------------------------&lt;br /&gt;
If you have downloaded the zip archive from the new moodle.org plugins page&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.- GO TO STEP 4 below&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (&#039;&#039;&#039;for latest developments&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
1.- Unzip the zip archive to your local computer.&lt;br /&gt;
&lt;br /&gt;
2.- This will give you a folder named something like &amp;quot;rezeau-moodle_qtype_regexp-ff8c6a1&amp;quot;. The end of the name may vary.&lt;br /&gt;
&lt;br /&gt;
3.- ***Rename*** that folder to &amp;quot;regexp&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.- Upload the regexp folder to &amp;lt;yourmoodle&amp;gt;/question/type/ folder.&lt;br /&gt;
&lt;br /&gt;
5.- Visit your Admin/Notifications page so that the new question type gets installed.&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Fitxer:alternate_answers.jpg&amp;diff=96372</id>
		<title>Fitxer:alternate answers.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Fitxer:alternate_answers.jpg&amp;diff=96372"/>
		<updated>2012-03-10T13:29:17Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: uploaded a new version of &amp;amp;quot;File:alternate answers.jpg&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Fitxer:alternate_answers.jpg&amp;diff=96371</id>
		<title>Fitxer:alternate answers.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Fitxer:alternate_answers.jpg&amp;diff=96371"/>
		<updated>2012-03-10T13:28:25Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: uploaded a new version of &amp;amp;quot;File:alternate answers.jpg&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Questionnaire_module&amp;diff=96324</id>
		<title>Questionnaire module</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Questionnaire_module&amp;diff=96324"/>
		<updated>2012-03-07T16:41:32Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* See also */ entered URL to new Moodle Plugins Directory&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questionnaire}}&lt;br /&gt;
&lt;br /&gt;
The Moodle &#039;&#039;&#039;Questionnaire module&#039;&#039;&#039; is a survey-like type of activity. It allows teachers to create a wide range of questions to get student feedback e.g. on a course or activities. The goals of the Questionnaire module are quite different from those of the Moodle &#039;&#039;&#039;Lesson&#039;&#039;&#039; or &#039;&#039;&#039;Quiz&#039;&#039;&#039; modules. With Questionnaire you do not test or assess the student, you &#039;&#039;gather data&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Summary of features==&lt;br /&gt;
Please look at the [[Adding/editing a questionnaire]] and [[Editing Questionnaire questions|Adding Questions]] pages for more information.  &lt;br /&gt;
&lt;br /&gt;
===Types of questions===&lt;br /&gt;
*Check Boxes&lt;br /&gt;
*Date Box&lt;br /&gt;
*Dropdown choices&lt;br /&gt;
*Essay box - HTML editor possible, set width and height of box&lt;br /&gt;
*Numeric - can set length and number of decimal places&lt;br /&gt;
*Radio buttons - have labels you determine for each question&lt;br /&gt;
*Scale - can customize in many ways&lt;br /&gt;
*Text box&lt;br /&gt;
*Yes/no&lt;br /&gt;
You can also place:&lt;br /&gt;
*Page breaks &lt;br /&gt;
*Labels - might be used to give an overview of next set of questions&lt;br /&gt;
&lt;br /&gt;
===Types of reports===&lt;br /&gt;
*Responses can be viewed by everyone or select group&lt;br /&gt;
*Responses can be exported&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* The Questionnaire plugin can be downloaded from the [http://moodle.org/plugins/view.php?plugin=mod_questionnaire Moodle Plugins Directory].&lt;br /&gt;
*Discussions: please create or find a discussion topic in the [http://moodle.org/mod/forum/view.php?f=469  Questionnaire Forum]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Statistical_survey Statistical_survey] From Wikipedia, the free encyclopedia.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Moodle 2.x&#039;&#039;&#039; will include a new module that combines the best of Questionnaire, Feedback and Survey into an upgrade for the Survey module. See [https://docs.moodle.org/en/Development:Survey_2_brainstorm Development: Survey 2 brainstorm]&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Questionnaire]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Discussi%C3%B3:Preg_question_type&amp;diff=93943</id>
		<title>Discussió:Preg question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Discussi%C3%B3:Preg_question_type&amp;diff=93943"/>
		<updated>2011-11-20T17:41:04Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: Created page with &amp;quot;=== Looking for missing things ===  &amp;#039;&amp;#039;Joseph Rezeau REGEXP question type has a special syntax for missing words feature, allowing to define an answer that would work when somethi...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Looking for missing things ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Joseph Rezeau REGEXP question type has a special syntax for missing words feature, allowing to define an answer that would work when something is absent in the answer (and give appropriate feedback to the student).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Please note that, starting with the version for moodle 2.1, my REGEXP question type accepts negative assertions (such as used in PREG question type) as well as the proprietary &#039;&#039;&#039;--.*\bnecessary\b.*&#039;&#039;&#039; syntax.&lt;br /&gt;
&lt;br /&gt;
@Oleg: you may wish to change your documentation to reflect this change in REGEXP.&lt;br /&gt;
&lt;br /&gt;
--[[User:Joseph Rézeau|Joseph Rézeau]] 01:41, 21 November 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92563</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92563"/>
		<updated>2011-10-23T21:43:28Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Display right answers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint/Help Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; (in 2.1 a &#039;&#039;&#039;Display Help Button&#039;&#039;&#039;) option to enable the student to &amp;quot;buy&amp;quot; the next correct letter. This letter will be added to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at &#039;&#039;&#039;No&#039;&#039;&#039;. The Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the &#039;&#039;&#039;Help me please&#039;&#039;&#039; button to buy a letter, that letter is added to his response. The 3rd line of the feedback zone shows the following information: added letter; penalty cost; total penalties so far. Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
{{Moodle 2.1}}If your Quiz settings &#039;&#039;Review options&#039;&#039; are set to display the Right answer (During the attempt or Immediately after the attempt etc.), when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade &amp;lt; 100% are also listed, with their grade value.&lt;br /&gt;
&lt;br /&gt;
[[Image:21 correct responses.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.1.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.1.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Fitxer:21_correct_responses.jpg&amp;diff=92562</id>
		<title>Fitxer:21 correct responses.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Fitxer:21_correct_responses.jpg&amp;diff=92562"/>
		<updated>2011-10-23T21:41:13Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92561</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92561"/>
		<updated>2011-10-23T21:36:16Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint/Help Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; (in 2.1 a &#039;&#039;&#039;Display Help Button&#039;&#039;&#039;) option to enable the student to &amp;quot;buy&amp;quot; the next correct letter. This letter will be added to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at &#039;&#039;&#039;No&#039;&#039;&#039;. The Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the &#039;&#039;&#039;Help me please&#039;&#039;&#039; button to buy a letter, that letter is added to his response. The 3rd line of the feedback zone shows the following information: added letter; penalty cost; total penalties so far. Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Display right answers===&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.1.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.1.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92560</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92560"/>
		<updated>2011-10-23T21:32:31Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Display Hint Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint/Help Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; (in 2.1 a &#039;&#039;&#039;Display Help Button&#039;&#039;&#039;) option to enable the student to &amp;quot;buy&amp;quot; the next correct letter. This letter will be added to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at &#039;&#039;&#039;No&#039;&#039;&#039;. The Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the &#039;&#039;&#039;Help me please&#039;&#039;&#039; button to buy a letter, that letter is added to his response. The 3rd line of the feedback zone shows the following information: added letter; penalty cost; total penalties so far. Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.1.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.1.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92559</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92559"/>
		<updated>2011-10-23T21:28:11Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Downloads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; (in 2.1 a &#039;&#039;&#039;Display Help Button&#039;&#039;&#039;) option to enable the student to &amp;quot;buy&amp;quot; the next correct letter. This letter will be added to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at &#039;&#039;&#039;No&#039;&#039;&#039;. The Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the &#039;&#039;&#039;Help me please&#039;&#039;&#039; button to buy a letter, that letter is added to his response. The 3rd line of the feedback zone shows the following information: added letter; penalty cost; total penalties so far. Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.1.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.1.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
====Learn more about regular expressions====&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92558</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92558"/>
		<updated>2011-10-23T21:27:09Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* About using Regular Expressions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; (in 2.1 a &#039;&#039;&#039;Display Help Button&#039;&#039;&#039;) option to enable the student to &amp;quot;buy&amp;quot; the next correct letter. This letter will be added to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at &#039;&#039;&#039;No&#039;&#039;&#039;. The Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the &#039;&#039;&#039;Help me please&#039;&#039;&#039; button to buy a letter, that letter is added to his response. The 3rd line of the feedback zone shows the following information: added letter; penalty cost; total penalties so far. Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====Downloads====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
* Download [http://moodle.org/plugins/view.php?plugin=qtype_regexp the latest 2.1.2 version (with behaviours)] from the new Plugins repository.&lt;br /&gt;
* IMPORTANT : for the 2.1.2 version, if you want the Help feature, you must also download and install the following 2 &amp;quot;question behaviours&amp;quot; from the new Plugins repository: [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp RegExp Adaptive mode with Help]  and [http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty RegExp Adaptive mode with Help (no penalties)].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92557</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92557"/>
		<updated>2011-10-23T21:18:34Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Feedback given by the Help me please button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; (in 2.1 a &#039;&#039;&#039;Display Help Button&#039;&#039;&#039;) option to enable the student to &amp;quot;buy&amp;quot; the next correct letter. This letter will be added to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at &#039;&#039;&#039;No&#039;&#039;&#039;. The Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help button===&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the &#039;&#039;&#039;Help me please&#039;&#039;&#039; button to buy a letter, that letter is added to his response. The 3rd line of the feedback zone shows the following information: added letter; penalty cost; total penalties so far. Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====About using Regular Expressions====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92556</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92556"/>
		<updated>2011-10-23T21:17:41Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Display Hint Button */ more Moodle 2.1 changes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; (in 2.1 a &#039;&#039;&#039;Display Help Button&#039;&#039;&#039;) option to enable the student to &amp;quot;buy&amp;quot; the next correct letter. This letter will be added to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at &#039;&#039;&#039;No&#039;&#039;&#039;. The Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Feedback given by the Help me please button===&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the &#039;&#039;&#039;Help me please&#039;&#039;&#039; button to buy a letter, that letter is added to his response. The 3rd line of the feedback zone shows the following information: added letter; penalty cost; total penalties so far. Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====About using Regular Expressions====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92555</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92555"/>
		<updated>2011-10-23T21:14:01Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Display Hint Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; (in 2.1 a &#039;&#039;&#039;Display Help Button&#039;&#039;&#039;) option to enable the student to &amp;quot;buy&amp;quot; the next correct letter. This letter will be added to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at &#039;&#039;&#039;No&#039;&#039;&#039;. The Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====About using Regular Expressions====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92554</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=92554"/>
		<updated>2011-10-23T21:10:52Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Display Hint Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; (in 2.1 a &#039;&#039;&#039;Display Help Button&#039;&#039;&#039;) option to enable the student to &amp;quot;buy&amp;quot; the next correct letter. This letter will be added to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at &#039;&#039;&#039;No&#039;&#039;&#039;. The Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Help button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the &#039;&#039;&#039;Help me please&#039;&#039;&#039; button to buy a letter, that letter is added to his response. The 3rd line of the feedback zone shows the following information: added letter; penalty cost; total penalties so far. Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, on the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, the response history shows &#039;&#039;Submit (with a request for help)&#039;&#039; with the response states before and after the letter was added.&lt;br /&gt;
&lt;br /&gt;
[[Image:21-addedletterhistory.jpg]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====About using Regular Expressions====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Fitxer:21-addedletterhistory.jpg&amp;diff=92553</id>
		<title>Fitxer:21-addedletterhistory.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Fitxer:21-addedletterhistory.jpg&amp;diff=92553"/>
		<updated>2011-10-23T21:07:43Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=91390</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=91390"/>
		<updated>2011-10-08T15:31:30Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Correct answer matching a regular expression pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it&#039;s blue, white, red&lt;br /&gt;
** it&#039;s blue, white and red&lt;br /&gt;
** It&#039;s blue, white, red&lt;br /&gt;
** It&#039;s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; option in order to allow the student to ask for a hint. This hint will add the next correct letter to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at No. In Moodle 1.9 and 2.0 the Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Hint button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1, because of a change in the scoring system, clicking the Hint button does not immediately take a penalty off the student&#039;s score. The penalty is taken from the score when the student clicks the Check button. Meanwhile, the Hint button is de-activated (greyed out), to prevent the student from getting &amp;quot;free Hint letters&amp;quot;! When the Hint button is grayed out, a ? button is displayed next to it explaining to the student&lt;br /&gt;
that they&#039;ll have to Check their answer before the Hint button is re-activated.&lt;br /&gt;
[[Image:regexp_click_check_button.jpg]]&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.0 each time a student clicks the Hint button to buy a letter, an invisible paragraph character ( ¶ ) is added to his response.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the Hint button to buy a letter, an ellipse character ( … ) is added to his response.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, that character is replaced by a [HINT] tag so the teacher knows that the Hint button was clicked for that response.&lt;br /&gt;
&lt;br /&gt;
On the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, a [Hint] mark is displayed whenever the student clicked the Hint button.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_hint_history.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 the Hint tag is followed by the letter which was added when the student clicked the Hint button.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_hint_history_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====About using Regular Expressions====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=91340</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=91340"/>
		<updated>2011-10-07T09:53:26Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Inserting regexp sub-questions in Cloze type questions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it’s blue, white, red&lt;br /&gt;
** it’s blue, white and red&lt;br /&gt;
** It’s blue, white, red&lt;br /&gt;
** It’s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; option in order to allow the student to ask for a hint. This hint will add the next correct letter to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at No. In Moodle 1.9 and 2.0 the Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Hint button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1, because of a change in the scoring system, clicking the Hint button does not immediately take a penalty off the student&#039;s score. The penalty is taken from the score when the student clicks the Check button. Meanwhile, the Hint button is de-activated (greyed out), to prevent the student from getting &amp;quot;free Hint letters&amp;quot;! When the Hint button is grayed out, a ? button is displayed next to it explaining to the student&lt;br /&gt;
that they&#039;ll have to Check their answer before the Hint button is re-activated.&lt;br /&gt;
[[Image:regexp_click_check_button.jpg]]&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.0 each time a student clicks the Hint button to buy a letter, an invisible paragraph character ( ¶ ) is added to his response.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the Hint button to buy a letter, an ellipse character ( … ) is added to his response.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, that character is replaced by a [HINT] tag so the teacher knows that the Hint button was clicked for that response.&lt;br /&gt;
&lt;br /&gt;
On the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, a [Hint] mark is displayed whenever the student clicked the Hint button.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_hint_history.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 the Hint tag is followed by the letter which was added when the student clicked the Hint button.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_hint_history_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;blue, white and red&amp;quot; as a correct answer as well as &amp;quot;Blue, White and Red&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====About using Regular Expressions====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=91339</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=91339"/>
		<updated>2011-10-07T09:44:16Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Inserting regexp sub-questions in Cloze type questions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it’s blue, white, red&lt;br /&gt;
** it’s blue, white and red&lt;br /&gt;
** It’s blue, white, red&lt;br /&gt;
** It’s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; option in order to allow the student to ask for a hint. This hint will add the next correct letter to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at No. In Moodle 1.9 and 2.0 the Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Hint button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1, because of a change in the scoring system, clicking the Hint button does not immediately take a penalty off the student&#039;s score. The penalty is taken from the score when the student clicks the Check button. Meanwhile, the Hint button is de-activated (greyed out), to prevent the student from getting &amp;quot;free Hint letters&amp;quot;! When the Hint button is grayed out, a ? button is displayed next to it explaining to the student&lt;br /&gt;
that they&#039;ll have to Check their answer before the Hint button is re-activated.&lt;br /&gt;
[[Image:regexp_click_check_button.jpg]]&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.0 each time a student clicks the Hint button to buy a letter, an invisible paragraph character ( ¶ ) is added to his response.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the Hint button to buy a letter, an ellipse character ( … ) is added to his response.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, that character is replaced by a [HINT] tag so the teacher knows that the Hint button was clicked for that response.&lt;br /&gt;
&lt;br /&gt;
On the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, a [Hint] mark is displayed whenever the student clicked the Hint button.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_hint_history.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 the Hint tag is followed by the letter which was added when the student clicked the Hint button.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_hint_history_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;it&#039;s blue, white and red.&amp;quot; as a correct answer as well as &amp;quot;It&#039;s blue, white and red.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;Blue, White and Red&amp;quot; as a correct answer (wrong capital letters).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====About using Regular Expressions====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=90845</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=90845"/>
		<updated>2011-09-30T14:16:34Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* Inserting regexp sub-questions in Cloze type questions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it’s blue, white, red&lt;br /&gt;
** it’s blue, white and red&lt;br /&gt;
** It’s blue, white, red&lt;br /&gt;
** It’s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; option in order to allow the student to ask for a hint. This hint will add the next correct letter to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at No. In Moodle 1.9 and 2.0 the Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Hint button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1, because of a change in the scoring system, clicking the Hint button does not immediately take a penalty off the student&#039;s score. The penalty is taken from the score when the student clicks the Check button. Meanwhile, the Hint button is de-activated (greyed out), to prevent the student from getting &amp;quot;free Hint letters&amp;quot;! When the Hint button is grayed out, a ? button is displayed next to it explaining to the student&lt;br /&gt;
that they&#039;ll have to Check their answer before the Hint button is re-activated.&lt;br /&gt;
[[Image:regexp_click_check_button.jpg]]&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.0 each time a student clicks the Hint button to buy a letter, an invisible paragraph character ( ¶ ) is added to his response.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the Hint button to buy a letter, an ellipse character ( … ) is added to his response.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, that character is replaced by a [HINT] tag so the teacher knows that the Hint button was clicked for that response.&lt;br /&gt;
&lt;br /&gt;
On the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, a [Hint] mark is displayed whenever the student clicked the Hint button.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_hint_history.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 the Hint tag is followed by the letter which was added when the student clicked the Hint button.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_hint_history_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Moodle Plugins repository, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;it&#039;s blue, white and red.&amp;quot; as a correct answer as well as &amp;quot;It&#039;s blue, white and red.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;blue, white and red.&amp;quot; as a correct answer (wrong capital letter).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====About using Regular Expressions====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=89542</id>
		<title>Regular Expression Short-Answer question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/2x/ca/index.php?title=Regular_Expression_Short-Answer_question_type&amp;diff=89542"/>
		<updated>2011-09-14T17:05:14Z</updated>

		<summary type="html">&lt;p&gt;Rezeau: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===The RegExp Short Answer Question===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;IMPORTANT NOTE&#039;&#039;&#039;.- &lt;br /&gt;
** The RegExp Short Answer question described in this documentation page is a 3rd-party plugin, which allows you to create questions for the &#039;&#039;&#039;&#039;&#039;Quiz&#039;&#039;&#039;&#039;&#039; activity. It is &#039;&#039;different&#039;&#039; from the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module.&lt;br /&gt;
** The documentation for the &amp;quot;Use regular expressions&amp;quot; option in the &#039;&#039;&#039;&#039;&#039;Lesson&#039;&#039;&#039;&#039;&#039; module is to be found at: [https://docs.moodle.org/en/Short_answer_analysis Short answer analysis].&lt;br /&gt;
&lt;br /&gt;
Like the Short Answer question, the RegExp Short Answer question expects the respondent to answer an &amp;quot;open&amp;quot; question with a word or a short phrase. However, the RegExp system system gives you access to a more powerful system for analysing the student&#039;s answers.&lt;br /&gt;
&lt;br /&gt;
===Correct answer matching a regular expression pattern===&lt;br /&gt;
&lt;br /&gt;
It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.&#039;&#039;&#039; Suppose your question was &amp;quot;What are the colors of the French flag?&amp;quot;. In the Answer 1 box you would type the &amp;quot;best&amp;quot; answer, e.g. &amp;quot;it&#039;s blue, white and red&amp;quot;. For more details, see [[#firstcorrect|First correct answer]] below.&lt;br /&gt;
&lt;br /&gt;
*In the Answer 2 box you would type this regular expression: &amp;quot;it’s blue, white(,| and) red&amp;quot; (quotes should not be typed, of course).&lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** it’s blue, white, red&lt;br /&gt;
** it’s blue, white and red&lt;br /&gt;
** It’s blue, white, red&lt;br /&gt;
** It’s blue, white and red&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
See [[#casesensivity|Case sensivity]] below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2&#039;&#039;&#039;. Question: &amp;quot;What is blue, or red, or yellow?&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;(|it&#039;s )a colou?r&amp;quot;. &lt;br /&gt;
* This will match any of those 4 responses:&lt;br /&gt;
** a colour&lt;br /&gt;
** a color&lt;br /&gt;
** it&#039;s a colour&lt;br /&gt;
** it&#039;s a color&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The beginning of this regular expression &amp;quot;(|it&#039;s )&amp;quot; will match either nothing or &amp;quot;it&#039;s &amp;quot; (i.e. &amp;quot;it&#039;s&amp;quot; followed by a space). It&#039;s also possibe to write this as &amp;quot;(it&#039;s )?a colou?r&amp;quot;.The ? (question-mark) means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 3.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;.&lt;br /&gt;
* Teacher Answer: &amp;quot;[bcr]at&amp;quot;. &lt;br /&gt;
* This will match: bat, cat or rat.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression &amp;quot;[bcr]at&amp;quot; is the exact equivalent of &amp;quot;(b|c|r)at&amp;quot;. Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, &amp;quot;[b|c|r]at&amp;quot; will NOT WORK CORRECTLY.&lt;br /&gt;
&lt;br /&gt;
===Escaping metacharacters===&lt;br /&gt;
&lt;br /&gt;
====Definition====&lt;br /&gt;
In the Regular Expressions syntax, a number of special characters or &#039;&#039;meta characters&#039;&#039; have special functions; but it is possible to force these special characters to be interpreted as normal (or &#039;&#039;literal&#039;&#039;) characters by preceding them with a so-called &#039;&#039;escape&#039;&#039; character, the backslash &amp;quot;\&amp;quot;. &lt;br /&gt;
Below is a (partial) list of those &#039;&#039;meta characters&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Accepted Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; are Answers which have a grade greater than zero, i.e. are &#039;&#039;totally&#039;&#039; (grade = 100%) or &#039;&#039;partially&#039;&#039; (grade &amp;gt; 0% &amp;lt; 100%) &#039;&#039;correct Answers&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In those Answers, if you need to use one or more &#039;&#039;meta characters&#039;&#039; for their &#039;&#039;literal&#039;&#039; value, you &#039;&#039;&#039;must&#039;&#039;&#039; &#039;&#039;escape&#039;&#039; them (i.e. precede them with a backslash). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 1.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;This computer costs 1000$ in the US.&amp;quot;, you must write the Answer as &amp;quot;This computer costs 1000\$ in the US\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 2.-&#039;&#039;&#039; If you want to accept the answer &amp;quot;Desktop computers are (usually) more powerful than laptops.&amp;quot;, you must write the Answer as &amp;quot;Desktop computers are \(usually\) more powerful than laptops\.&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
* You can mix metacharacters that have a special function with others that have a literal value, within one Answer.&lt;br /&gt;
&#039;&#039;&#039;Example 3.-&#039;&#039;&#039; If you want to accept both answers &amp;quot;Computers are (usually) cheaper than cars.&amp;quot; and &amp;quot;Computers are (usually) less expensive than cars.&amp;quot;, you must write the Answer as &amp;quot;&amp;quot;Computers are \(usually\) (cheaper|less expensive) than cars.&amp;quot;&amp;quot;. &lt;br /&gt;
* In the &#039;&#039;&#039;Accepted Answers&#039;&#039;&#039; boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some &#039;&#039;meta characters&#039;&#039; which match a potentially infinite number of sentences.&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;can&#039;&#039;&#039; use for their regexp functions:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;( ) [ ] ? |&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* List of &#039;&#039;meta characters&#039;&#039; which you &#039;&#039;&#039;cannot&#039;&#039;&#039; use for their regexp functions, and can only be used for their &#039;&#039;literal&#039;&#039; value (and must be &#039;&#039;escaped&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * + ? { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====In Incorrect Answers====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Incorrect Answers&#039;&#039;&#039; are Answers which have a grade equal to zero (or None).&lt;br /&gt;
When you write those Incorrect Answers, you can use the whole range of &#039;&#039;meta characters&#039;&#039; for their special function value:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;. ^ $ * ( ) [ ] + ? | { } \ /&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For examples of use, see &#039;&#039;&#039;Detecting missing required words or character strings&#039;&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
====Answers Validation====&lt;br /&gt;
&lt;br /&gt;
When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.&lt;br /&gt;
&lt;br /&gt;
The Validation engine also checks that your parentheses and square brackets are correctly balanced.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note.-&#039;&#039;&#039; The Validation engine works better in the Moodle 2.1 version of the REGEXP question type than in previous versions. The faulty Answer text is &amp;quot;underlined&amp;quot; with the list of errors, as in the attached screenshot.&lt;br /&gt;
[[Image:Errors_en.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Detecting missing required words or character strings===&lt;br /&gt;
&lt;br /&gt;
Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer to take care of this. Any Teacher Answer which begins with a double hyphen will analyse the student’s response to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Feedback message is displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 4. &#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer 2: --.*blue.*&lt;br /&gt;
* Sample student Response: &amp;quot;it&#039;s red and white&amp;quot;&lt;br /&gt;
* Feedback 2: The color of the sky is missing!&lt;br /&gt;
&lt;br /&gt;
Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string &amp;quot;blue&amp;quot;, preceded with anything and followed by anything is absent from the student&#039;s answer. Please note that the use of the asterisk is different in Moodle&#039;s &amp;quot;normal&amp;quot; Short Answer question type and in the RegExp question type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 5.&#039;&#039;&#039; Question: &amp;quot;Name an animal whose name is made of 3 letters and the middle letter is the vowel &#039;&#039;a&#039;&#039;&amp;quot;. &lt;br /&gt;
* Teacher Answer: &amp;quot;--[bcr]&amp;quot;. &#039;&#039;&#039;OR&#039;&#039;&#039; * Teacher Answer: &amp;quot;--(b|c|r)&amp;quot;. &lt;br /&gt;
* Feedback: &amp;quot;Your answer should start with one of these letters: b, c or r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 6.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(blue|red|white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s black and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not even found one of the colors of the French flag!&amp;quot;&lt;br /&gt;
* Sample student Response #2: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the &amp;quot;missing condition&amp;quot; is considered false, and the response analysis continues to the next Answer&#039;s regular expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example 7.&#039;&#039;&#039; Question &amp;quot;What are the colors of the French flag?&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Teacher Answer: &amp;quot;--.*(&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;blue&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039;white).*&amp;quot;&lt;br /&gt;
* Sample student Response #1: &amp;quot;It&#039;s blue and orange.&amp;quot;&lt;br /&gt;
* Feedback: &amp;quot;You have not found all the colors of the French flag&amp;quot;.&lt;br /&gt;
* Sample student Response #2: &amp;quot;white blue red&amp;quot;.&lt;br /&gt;
* Feedback: None, the analysis continues to the next Teacher Answer expression.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Explanation&#039;&#039;&#039;&#039;&#039;.- The regular expression looks for a missing word among all of those listed between brackets and separated by the &amp;amp;&amp;amp; double character combination. Only if all of those words are present, will the &amp;quot;missing condition&amp;quot; be considered false, and the response analysis continue to the next Answer&#039;s regular expression. Please note that the list of parenthesized words must begin with the &amp;amp;&amp;amp; character sequence.&lt;br /&gt;
&lt;br /&gt;
===Entering Answers in Edit Question mode (teacher)===&lt;br /&gt;
&lt;br /&gt;
====Display Hint Button====&lt;br /&gt;
&lt;br /&gt;
It is possible for the teacher to select a &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; option in order to allow the student to ask for a hint. This hint will add the next correct letter to the student&#039;s input response field and - if the penalty scheme has been enabled in the Quiz settings - will cost the student one penalty factor. By default the Display Hint button value is set at No. In Moodle 1.9 and 2.0 the Hint button will only be available to quizzes which have their &#039;&#039;&#039;Adaptive mode&#039;&#039;&#039; set to &#039;&#039;Yes&#039;&#039;, as it does not make sense to enable the Hint button for non-adaptive tests. In Moodle 2.1, the Hint button will only be available to quizzes that have their &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode set to &#039;&#039;Adaptive&#039;&#039; or &#039;&#039;Adaptive (no penalties)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1, because of a change in the scoring system, clicking the Hint button does not immediately take a penalty off the student&#039;s score. The penalty is taken from the score when the student clicks the Check button. Meanwhile, the Hint button is de-activated (greyed out), to prevent the student from getting &amp;quot;free Hint letters&amp;quot;! When the Hint button is grayed out, a ? button is displayed next to it explaining to the student&lt;br /&gt;
that they&#039;ll have to Check their answer before the Hint button is re-activated.&lt;br /&gt;
[[Image:regexp_click_check_button.jpg]]&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.0 each time a student clicks the Hint button to buy a letter, an invisible paragraph character ( ¶ ) is added to his response.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 each time a student clicks the Hint button to buy a letter, an ellipse character ( … ) is added to his response.&lt;br /&gt;
&lt;br /&gt;
When the teacher views the quiz results, that character is replaced by a [HINT] tag so the teacher knows that the Hint button was clicked for that response.&lt;br /&gt;
&lt;br /&gt;
On the &#039;&#039;&#039;&#039;Review Attempt&#039;&#039;&#039;&#039; pages, &#039;&#039;&#039;&#039;History of responses&#039;&#039;&#039;&#039; section, a [Hint] mark is displayed whenever the student clicked the Hint button.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_hint_history.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}In Moodle 2.1 the Hint tag is followed by the letter which was added when the student clicked the Hint button.&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_hint_history_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;casesensivity&amp;quot;&amp;gt;Case sensitivity&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.9, by default a regular expression match is case sensitive; to make the match case insensitive you must add the &#039;&#039;&#039;/i&#039;&#039;&#039; parameter right at the end of your expression. For instance the expression &amp;quot;it’s blue, white(,| and) red/i&amp;quot; would match all of the above responses plus any combination of capital letters: It&#039;s blue, white, red; IT&#039;S BLUE, WHITE, RED, etc. &lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 and 2.1, the editing form features a &#039;&#039;Case sensitivity&#039;&#039; setting, which is valid for &#039;&#039;all of the answers&#039;&#039; of the current question. You should not add an &#039;&#039;&#039;/i&#039;&#039;&#039; parameter at the end of your regular expressions. You may need to edit questions authored in 1.9 when you upgrade to 2.0 and remove any &#039;&#039;&#039;/i&#039;&#039;&#039; parameters from your regular expressions.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;span id=&amp;quot;firstcorrect&amp;quot;&amp;gt;First correct answer&amp;lt;/span&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
For Answer 1 you must enter an answer text which a) is the &amp;quot;best&amp;quot; possible answer; b) is &#039;&#039;&#039;not&#039;&#039;&#039; a regular expression or - more exactly - &#039;&#039;will not be interpreted as a regular expression&#039;&#039; but &amp;quot;as is&amp;quot; and c) has a Grade value of 100%. You will notice that when you create a new regexp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.&lt;br /&gt;
&lt;br /&gt;
Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?&lt;br /&gt;
&lt;br /&gt;
Answer 1: It cost $1,000.&lt;br /&gt;
&lt;br /&gt;
Answer 2: It cost ( me)?\$1,000\.&lt;br /&gt;
&lt;br /&gt;
In Anwer 1 you just type the expected answer &amp;quot;as is&amp;quot;. The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun &amp;quot;me&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Other answers====&lt;br /&gt;
&lt;br /&gt;
Any answers with a Grade higher than 0% must be entered as valid regular expressions &#039;&#039;which can yield acceptable alternative answers&#039;&#039; (regardless of the Grade being less than 100%).&lt;br /&gt;
&lt;br /&gt;
This means that some regular expressions, which are perfectly valid and would correctly analyse the student&#039;s (correct) answer are not recommended. The only case where they would work is a) if your question&#039;s &#039;&#039;&#039;Display Hint Button&#039;&#039;&#039; is set at No and b) your quiz &#039;&#039;&#039;Adaptative Mode&#039;&#039;&#039; is set at No. This means that you must &#039;&#039;not&#039;&#039; enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen &amp;quot;--&amp;quot;, used for detecting missing character strings.&lt;br /&gt;
&lt;br /&gt;
===Previewing questions in popup window (teacher only)===&lt;br /&gt;
&lt;br /&gt;
When the teacher previews a question in the popup preview question window it is now possible to display all of the acceptable alternative answers. Those alternative answers are automatically generated from the regular expressions you have entered when creating the question which carry a grade higher than 0%. The very first acceptable answer is printed as is at the top of the list. This is followed by all the other alternative acceptable answers, consisting of a) the Grade attributed; b) a reminder of the regular expression you entered and c) a list of all alternative answers.&lt;br /&gt;
&lt;br /&gt;
The only check done by the programme for the validity of your regular expressions consists in checking that opened parentheses and square brackets are correctly closed. If your parentheses and square brackets are not correctly closed, a warning message will be displayed showing the number of each. You should immediately edit the faulty question.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended to use the preview popup window systematically immediately after having created or edited a regexp type question, and to click on the &#039;&#039;&#039;Show alternate answers&#039;&#039;&#039; button in order to check the validity of one&#039;s regular expressions.&lt;br /&gt;
&lt;br /&gt;
[[Image:alternate_answers.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Automatic formatted extra feedback===&lt;br /&gt;
&lt;br /&gt;
When a student (or teacher in Preview Question mode) submits a response to a REGEXP question, 3 types of feedback messages are displayed (in Adaptive mode).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}Please note that in Moodle 2.1 the REGEXP question can be used in any &#039;&#039;&#039;Question behaviour&#039;&#039;&#039; mode. However, it is advised to create quizzes containing only REGEXP questions or containing other types of questions, but &#039;&#039;preferably&#039;&#039; if the quiz&#039;s &#039;&#039;&#039;&#039;&#039;Question behaviour / How questions behave&#039;&#039;&#039;&#039;&#039; setting is set to &#039;&#039;Adaptive mode&#039;&#039; (with or without penalty).&lt;br /&gt;
* The standard correct/incorrect Quiz message (plus the color associated with either state).&lt;br /&gt;
* The Feedback message entered by the question creator for each Teacher Answer.&lt;br /&gt;
* An extra feedback system is automatically provided, displaying the student&#039;s submitted responses, with the following format codes:&lt;br /&gt;
** the beginning of the student&#039;s submitted response which best matches one of the Alternate Answers is displayed in blue;&lt;br /&gt;
** any words from the submittted response which are present in the potential Alternate Answers following the initial correct part submitted are colored in red;&lt;br /&gt;
** any words not present in the potential Alternate Answers following the initial correct part submitted are colored in red and formatted as strikethrough.&lt;br /&gt;
The meaning of those colors etc. may need to be explained to the student before they take the quiz, especially the difference between &amp;quot;red&amp;quot; and &amp;quot;red plus strikethrough&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;.- The coloring system is different in Moodle 1.9 and 2.0. The system explained and illustrated here is the one currently in use in Moodle 2.0 and (slightly different) in Moodle 2.1.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback.jpg]]&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}&lt;br /&gt;
&lt;br /&gt;
[[Image:regexp_colored_feedback_21.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Inserting regexp sub-questions in Cloze type questions===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Important notice&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
The RegExp question type is &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039; recognized by the standard Moodle Cloze question type. If you want to use it you&#039;ll have to replace the question/type/multianswer/questiontype.php file from your standard Moodle with the hacked file(s) available from the Modules and Plugins database, according to the instructions given there.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Syntax for inserting regexp sub-questions in Cloze type questions.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.1}}{{Moodle 2.0}}In Moodle 2.0 or 2.1, use &#039;&#039;&#039;REGEXP&#039;&#039;&#039; or shorter &#039;&#039;&#039;RX&#039;&#039;&#039; coding for questions which ignore case&lt;br /&gt;
&lt;br /&gt;
* The colors of the French flag are {:REGEXP:=blue, white and red.#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RX:=blue, white and red.#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will accept &amp;quot;it&#039;s blue, white and red.&amp;quot; as a correct answer as well as &amp;quot;It&#039;s blue, white and red.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
use &#039;&#039;&#039;REGEXP_C&#039;&#039;&#039; or shorter &#039;&#039;&#039;RXC&#039;&#039;&#039; coding for questions in which case matters&lt;br /&gt;
* The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.&lt;br /&gt;
* The colors of the French flag are {:RXC:=blue, white and red#Correct!}.&lt;br /&gt;
&lt;br /&gt;
Will not accept &amp;quot;blue, white and red.&amp;quot; as a correct answer (wrong capital letter).&lt;br /&gt;
&lt;br /&gt;
Please note that, as explained above, the very first answer &#039;&#039;must&#039;&#039; be Graded 100% (in Cloze type question syntax, all correct is either &#039;&#039;&#039;=&#039;&#039;&#039; or &#039;&#039;&#039;100%&#039;&#039;&#039;) and it must &#039;&#039;not&#039;&#039; be a regular expression.&lt;br /&gt;
&lt;br /&gt;
Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;Hint&#039;&#039; button is not available for a regexp question embedded in a Cloze-type question.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
====About using Regular Expressions====&lt;br /&gt;
* Download [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 the Regular Expression Short-Answer question type] from the Moodle Modules &amp;amp; plugins page.&lt;br /&gt;
*[http://www.regular-expressions.info/tutorial.html Regular Expressions Tutorial] A complete introduction to the topic.&lt;br /&gt;
*[http://www.regexplanet.com/simple/index.html Regular Expression Test Page] Test your regular expressions on a variety of &amp;quot;answers&amp;quot;. Very useful for this question type; will save you a lot of time.&lt;br /&gt;
&lt;br /&gt;
====Other Moodle question types based on regular expressions====&lt;br /&gt;
[https://docs.moodle.org/dev/The_OU_PMatch_algorithm The OUP&#039;s PMatch]&lt;br /&gt;
&lt;br /&gt;
[https://docs.moodle.org/20/en/Preg_question_type Oleg Sychev&#039;s Preg question type]&lt;br /&gt;
&lt;br /&gt;
[[fr:question/type/regexp]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Rezeau</name></author>
	</entry>
</feed>