What regular expression syntax will work in short answer questions

Events happening in the community are now at Drupal community events on www.drupal.org.
scottiw2000's picture

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

scottiw2000's picture

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

kinghfb's picture

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".

Quiz

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week