Hello,
I have been exploring the possibilities of cr in implementing an HTML-question-type which has been successful and is exciting.
However, I need some direction on how to implement the regular expression grader for the new question-type.
Here's a scenario: I am expecting the opening and closing tag with some data in the answer But I want to provide the flexibility of expecting any data in between the opening and ending tag. i.e. <h1>{any data}</h1>. I am using the Python HTML Parser. Hence when any code is provided as the answer to a question, it detects the tags sequentially. So I want to write a regular expression that would accept any word character.
I am not sure where exactly to write the regular expression whether in the Expected column of the test case when defining the question-type or in the test case for each question that uses the newly defined question-type.
I have already selected the Regular Expression as the Grading option when I was creating the Question-type I'm using for this question. I am currently trying to write the regex in the Expected column of a test case of this question but it isn't working.
This is the results:
But I want to accept any word character for the Encountered some data row using regex, how do I go about it?
Thanks in advance.
The Expected field is a single regular expression, without PERL-type delimiters. Thus you should drop the '/' characters and you might as well drop the parentheses as well, as there's no way you can get at the captured text. So your Expected field should be just
Encountered a start tag: h1 Encountered some data : .* Encountered an end tag : h1
I'll update the in-line documentation in the next release to make this a bit clearer.
Alternatively, since you're apparently using a Python question type, you could do the regular expression matching within the template instead and, using an Equality Grader, print a very simple output like "OK" if everything matches and a much more comprehensive error output otherwise.
I will implement the alternative solution as well but thank you. That was what I needed