Lesson problem - Ereg Error

Lesson problem - Ereg Error

by Philip Norton -
Number of replies: 5
Hi there,

I am composing a lesson with some short answer questions for a JAVA course that I am running at a K12 school. I am busy working on a section on arrays and the question in particular that is giving me problems is a short answer question.

The short answers that I would like to have as answers are:

int*[] dataArray*=*new int*[*total*]*;

and:

*

Where the first option is correct (the stars are there to allow for white-space differences) and the second option is the catchall for incorrect answers.

I'm not sure if this is working, or even if I have gone about it correctly!

When I test the question (and give it a correct answer), I get the following error:

Warning: ereg(): REG_EBRACK:tbrackets ([ ]) not balanced in C:\webserver\intranet\docs\mod\lesson\lesson.php on line 351

Does anyone have any ideas?

Many thanks!

Philip Norton
Average of ratings: -
In reply to Philip Norton

Re: Lesson problem - Ereg Error

by Philip Norton -
Hmmm... This works if I write my answer as follows:

int*\[\] dataArray*=*new int*\[*total*\]*;

Why do the square brackets need to be escaped? I assume it has something to do with the regular expression checker? Can't this be done automatically?

This has pointed out that some of my other answers might not be correct. What other characters are "understood" by the regular expression checker?

Many thanks!

Philip Norton

In reply to Philip Norton

Re: Lesson problem - Ereg Error

by Ray Kingdon -
Yes, the present of *(s) kicks in a regular expression comparison. Square brackets are special characters in regexps and thus should be escaped. It should work as you have it, though some testing is always needed wink.

[Looking at the current code for short answers I don't think it handles wild characters (*). Perhaps it moved somewhere else?]
In reply to Ray Kingdon

Re: Lesson problem - Ereg Error

by Philip Norton -

Hi Ray,

Thanks for your reply. Could I bug you one step further? Could I better write that expression so that the *'s can only be replaced with spaces? I'm not at all familiar with regular expressions... thoughtful

As it stands, I think it will work with the majority of cases, but the perfectionist in me wants a more exact answer!

Many thanks,

Philip

In reply to Philip Norton

Re: Lesson problem - Ereg Error

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Philip!

This is in answer to your queries regarding correct answer analysis of student responses entered in the short answer exercise type of the Lesson module.

The correct way to match complex reponses to a short answer question is to use regular expressions. Mastering regular expressions is not so easy, but once you understand them they are a very powerful tool for answer analysis (which is what you are after).

Unfortunately, at the moment regular expressions are not implemented in the lesson module (nor in the Quiz module).

I have developed a working version of the lesson.php module which includes regular expressions and sent it to Ray some time in July. Ray, are you still interested in incorporating regular expressions into the Lesson Module ?

In the meantime, Philip, if you want to test the "power" of regular expressions, you can go to my testing page: http://rezeau.org/webCT/expandRegexpToString.htm

in the regExp box enter: int\s*\[\] dataArray\s*=\s*new int\s*\[\s*total\s*\]

in the String box, enter: int [] dataArray = new int [total]

Finally, the answer to your question of allowing any number of spaces (and no other characters) is dealt with by the \s* string in the REgular Expression to be matched (\s = ny single white-space character ; * = the preceding character 0 or infinite number of times)

Hope that helps,

Joseph_R

In reply to Joseph Rézeau

Re: Lesson problem - Ereg Error

by Philip Norton -

Many thanks Ray,

I do hope that some form of specifying whitespace at least can make its way into the lesson (and, for that matter quiz!) module.

Sincerely,

Philip