Posted by scottiw2000 on January 11, 2011 at 5:06pm
I'm trying to use regular expressions to evaluate short-answer questions with the quiz module (rc10), and I keep getting error messages. The module doesn't seem to recognize things like brackets where they are standard in regex syntax. Can anyone tell me what regex expressions are accepted by the module? Is it documented anywhere?
PS, I've had a support-request posted on the issue queue for 5 days with no response at all. Kind of disappointing.
Comments
Starting to figure this out
Ok, after some digging I've found out that the regular expression (evaluated by the preg_match() php function) needs to be surrounded by / delimiters like this: /xxx/
After the final forward slash you can include letters to turn on special matching modes:
/xxx/i searches for xxx without case sensitivity
/xxx/u searches for xxx as a utf-8 unicode string (default is ascii)
etc.
Between those two forward slashes you can use whatever perl regex syntax you want. This is a really powerful part of the quiz module, and it makes the module really usable for the kind of work I'm doing (testing language competency) where there are multiple complex right answers. I just wish it were documented better for those of us who never learned perl. Is there a documentation wiki for the quiz module where I could contribute to documenting the regex feature?
Solution confirmed
Just confirming the above solution worked. You'd generally throw the RegEx between a couple of slashes (I personally use @) in code, but this isn't documented well at all.
Also, it has the unfortunate side effect of displaying to the user the RegEx as the "correct answer".