I am impressed by the Joseph Rézeau plugin for the Regular Expression Short Answer question type. I was initially puzzled and surprised that it does not appear to support all standard regular expressions.
I have only yesterday installed the plugin (Moodle 1.8.6) and read some of the forum threads – so apologies – I will not have a full grasp of the rationale behind the implementation. My understanding is:
-
The plugin is really aimed at providing appropriate feedback in the case of 'incorrect' answers.
-
Support for certain metacharacters (* and +) is not provided – because of a problem with providing hints and infinite matches.
Is there still a need, within core Moodle or via a plugin, for standard regular expressions? My instinct is Yes. I would be very happy with a ShortAnswer / EmbeddedAnswer option to include a standard regular expression. My concern is to provide flexible, correct or partially correct answers – it could be I have unrealistic expectations about what is achievable.
As an example, here's a regular expression provided by Joseph Rézeau for a maths question: What are the factors of 15?
See: http://moodle.org/mod/forum/discuss.php?d=79116
The factors are 1 3 5 15
(1 3 5 15|1,3,5,15|1,3,5 and 15|1, 3, 5 and 15)
That is probably similar to the Reg Ex that I would use and I would instruct students to write the list in increasing order, with numbers separated by a comma or space. But how do you give marks for those who change the order as in 1 5 3 15, which is technically correct. I suspect that a full Reg Ex solution may not be possible – but it is, I think, certainly not possible using the Reg Ex Short Answer plugin – or if it is, please, show me, without using 48 permutations.
In order to achieve a compromise solution you may have to guess the likely incorrect answers. It is not too difficult to check that 1, 3, 5 and 15 are all included in the answer – but how would you do that exclusively? For example, the student's answer could be 1 3 5 6 9 10 12 15 (clearly wrong) and the Reg Ex must exclude the 6 9 10 12, otherwise the answer is marked 'correct'.
To exclude those numbers requires an expression something like:
(?!.*\b(6|9|10|12)\b)
You could decide to filter other likely wrong answers. A possible common error is to list multiples such as 30, not factors, and so you could exclude every number from 1 to 30, except the correct values, 1, 3, 5 and 15.
I am no expert on regular expressions – maybe there is an easier way. Also, maybe this question on factors is not the best example, but the Reg Ex Short Answer question (which does not support ".*") does not seem to provide any possibility of implementing the sort of expression needed, where the keywords (in this example, the numbers) must all be present and order is not important.
Perhaps a better example is the flag colours question used by Joseph Rézeau. You could ask for the three colours of a national flag, selected from a list of seven colours. Eliminating the four incorrect colours using the regular expression is then feasible, in the event that an answer contains four or more colours, i.e. the correct three and one or more incorrect. Of course, you still need to check that the three correct colours are present (in any order). Also, I understand that in the original flag question, the order and the sentence construction were also important.
So, this is my question, which must have been asked before but I can find no answer. Is there a fairly simple way to modify the standard Short Answer code so that standard regular expressions are processed or, alternatively to modify the plugin code? I am assuming (excuse my ignorance/ naivety) that the correct answer (in this case a regular expression) is held in the database and that perhaps only a few lines of code need to be changed. One disadvantage would be the need to escape all metacharacters that form part of an answer – but I can live with that. If anyone can point me in the right direction, I would appreciate. Thank you.