Your Moodle version

Question types: Perl-Compatible Regular Expression

Maintained by Picture of Oleg Sychev Oleg Sychev
A question that could check student's response against several regular expressions and could give next character and next word hints. If you do not know what regular expression is, it could also work like Moodle Shortanswer question with hints, just choose "Moodle shortanswer" as notation and you could enter answers just like in shortanswer question type.

This question requires 5 other plugins to work. If you want easy install, download full archive from our BitBucket site. You could unpack it into Moodle core folder (the one with config.php) and it will place anything where it belongs.

If you want to fully use Authoring Tools, you should also have Open Source Graphviz packet installed and path to it specified into Moodle. It is necessary to draw Syntax Tree and Explaining Graph.


This plugin is part of set Perl-Compatible Regular Expression Set.


Picture of Oleg Sychev
Oleg Sychev (Lead maintainer): Idea, design, question type and behaviours code, hinting, error reporting, regular expression testing (authoring tool)
Picture of Valeriy Streltsov
Valeriy Streltsov: Regex parsing, NFA regex matching engine, matchers testing, backup&restore, unicode support, selection in regex text (in authoring tools)
Picture of Dmitry Pahomov
Dmitry Pahomov: Regex description (authoring tool)
Picture of Vladimir Ivanov
Vladimir Ivanov: Explaining graph (authoring tool)
Picture of Grigory Terekhov
Grigory Terekhov: Syntax tree (authoring tool)
Picture of Elena Lepilkina
Elena Lepilkina: Assertions support
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Jarosław Maciejewski
    Sat, Oct 18, 2014, 8:52 PM
    Fatal error: Cannot redeclare qtype_preg_fa_avoid_wordbreaks_test::test_two_lines() in /warehouse/lampp/htdocs/moodle/question/type/preg/tests/fa_intersection_test.php on line 540
  • Picture of Oleg Sychev
    Sat, Oct 18, 2014, 9:48 PM
    Thank for the notion, Jaroslaw, but some uint-tests there (like fa_intersection_test.php) are part of ongoing development features for future releases and code under testing doesn't called anywhere from released production code.
  • Picture of Sepp Hofbauer
    Tue, Nov 18, 2014, 12:17 AM
    Thanks for the nice plugin. A typical problem is an correct answer ( as in your example) like
    "blue, white, red". Is it possible to add an matching engine which goes through all answers and calcs additive the matching percents, eg.:
    33% for .*blue.*
    33% for .*white.*
    33% for .*red.*
    (-10% for not .*,.*and.*)
    ? This would strongly simplify the permutations of partly correct answers.

  • Picture of Oleg Sychev
    Tue, Nov 18, 2014, 6:56 AM
    Hi, Sepp. This is more another grading algorithm than matching engine. It will also require separate interface to enter answers, as you will need to enter both complete (for hinting generation) and partial answers. Also, not in every case you would want to allow elements of the answer in any order. This will require thorought discussion. Please create an issue on to discuss this.
  • Picture of Oleg Sychev
    Tue, Nov 18, 2014, 7:28 AM
    Sepp, if you are really into creating an asnwers from some words in some order, this (my) question type may suit you much better - . It can break up answer to words, detect missing, extraneous and misplaced words and grade it accordingly, giving hints.

    Regular expressions are used to write all kind of nasty thing, they can be non-linear, use repetitions, backreferences, recursion etc. I can not imagine right now how what you want should behave for complex regular expression. If you still wish to discuss this to example - let's do it on the tracker (link above). But I think than CorrectWriting question will give you what you want without regular expressions.
  • Picture of Sepp Hofbauer
    Fri, Nov 21, 2014, 2:40 AM
    Thanks for your quick response. I had a look on your correct writing plugin and it seems very useful for learning.
    I think, to grade fully correct answers with regex is a trivial thing. The difficult job is to grade partially correct answers.
    My idea was to search (with regex) in the student's answer for special expressions and have points for it.
    e.g: in Java: for(int i=0;i<10;i++)
    One regex checks for fully correctness; if not a serie of regexes looks for correct parts like
    "int i=0" or "i<10|i<=9" or "i++|i+=1|i=i+1|i=1+i" or "for(.*;.*;)"
    and have 30%+30%+30%+5% points for it. A student answer can have a combination of errors, but the correct parts give percents of points.
    This is what I meant. Each regex needs two fields for successor regexes for matched / unmatched. (like in the math plugin STACK). So it is possible to build up a decision tree with matching or unmatching regexes. (Sure, I can use use the math plugin and take usage of maxima's regex capabilities, but this plugin is more performant)
  • Picture of Oleg Sychev
    Fri, Jul 3, 2015, 5:47 AM
    Sepp, it's not that easy. You example with Java would accept "for(i++;int i=0; i<10)" as a correct answer which is far from what Java expects. It also will accept something like for(int i=0 some_strange_additionally_garbage_can_be_inserted_in_many_places;i<10;i++)" as a correct too,
  • Picture of Oleg Sychev
    Fri, Jul 3, 2015, 5:48 AM
    Well, not correct but 95% for such answers is too much IMHO.
Please login to post comments