RegEx Matcher

Question types ::: qtype_regexmatch
Maintained by Thomas Öttl
Grades student answers based on a single or multiple regular expressions.

RegEx Matcher 2025072400

Moodle 4.1, 4.2, 4.3, 4.4, 4.5, 5.0
Released: බදාදා, 6 අගෝස්තු 2025, 4:26 PM

Moodle Question Type Regex Match

Grades student answers based on a single or multiple regular expressions.

Current capabilities

  • Add "Regex Matcher" question type
  • Edit question title, text, and feedback
  • Add as many regular expressions (patterns) with different grades as needed
    • Pattern must be compatible with preg_match. A cheat sheet for preg_match can be found here
    • There is a help button (?) next to the first three Regular Expression, which show most of the syntax.
    • The student's answer must completely match the pattern to receive the selected grade. Technically this means:
    • "^" and "$" are always added to the beginning and end of the pattern respectively.
    • Flag "m" (MULTILINE) is always set
    • CASELESS ("i") and DOTALL ("s") flag can be selected
    • CASELESS: Pattern ignores case when matching
    • DOTALL: All dots (".") inside the pattern also match newlines.
    • Optionally the students answer can be trimmed from any leading and trailing spaces
    • Shell Options: Two options exist which make writing regular expressions for shell-code easier.
    • Sanity Check:
    • At least one regular expression with a grade of 100% must exist.
  • Hints: If the test allows multiple tries (with possible grade reduction), hints can be set for each try
  • Start test, grade and get feedback
  • Backup/Restore question

Moodle Installation

References for installation on Windows and Ubuntu are given below.

Windows

Ubuntu

Regex Match Installation Using Git (for development)

To install using git for the latest version (the master branch), type this command in the <moodle-installation>/question/type folder of your Moodle install:

git clone https://github.com/lni-dev/moodle-qtype_regexmatch.git regexmatch

After the installation the moodle administration website Website Administration must be visited.

Regex Match Installation/Update (for use)

The Zip-File can be installed through the moodle Administration site: Site administration > Plugins > Install plugins. More Information about installing plugins can be found here.

IDE

The following (example) IDEs can be used to edit the code.

PHPStorm

Eclipse

Development Notes and Troubleshooting

Some notes and troubleshooting occurred during development

Course backup remains on pending

This is a problem, if moodle is installed locally. Asynchronous backups must be disabled. This can be done in the moodle administration site: Site administration > Courses > Asynchronous backups

Creating a new version

Some steps must be taken if a new version if the plugin should be released. 1. Increase the plugin-version in the file version.php. More information can be found in the specified file. 2. If any changes regarding the database were taken (e.g. a column/table added or removed), this can be done in db/update.php. The required code can mostly be generated using the moodle XMLDB Editor. More Information about the XMLDB Editor can be found here. 3. Create the new Zip for the Plugin: Zip the contents of the Plugins, so that the following structure is created: regexmatch.zip | - db | - ... | - ... | - version.php - The .git and .idea folder should not be added to the zip file.

supported PHP Version and Moodle Version

Make sure, that the Plugin supports the lowest PHP version possible for your supported moodle version. (Set the PHP Language Level to that version) The supported moodle version must be set in `version.php. - Required PHP Version - Moodle Versions

database errors after installation

  • Check the state of the required databases using the Moodle Adminer Plugin (Site administration > Server > Moodle Adminer) and "repair" the database using a customized version with a update.php, which will repair the database. It is possible, that simply allowing update.php to run again may fix the problem.

Uninstalling the plugin

To uninstall the plugin no questions of this plugin may exist. To achieve this, all entries in the table mdl_question where the variable qtype is regexmatch must be deleted. The Plugin Moodle Adminer can be used to easily do this.

Development Links with useful information

Additional advice can be found here: - https://github.com/marcusgreen/moodle-qtype_TEMPLATE/wiki - Backup/Restore: https://moodle.org/mod/forum/discuss.php?d=397659

Version information

Version build number
2025072400
Maturity
Stable version
MD5 Sum
389c1f0cf0b7af9a022e144b42561134
Supported software
Moodle 4.1, Moodle 4.2, Moodle 4.3, Moodle 4.4, Moodle 4.5, Moodle 5.0
  • The more recent release 2025102700 exists for Moodle 4.1
  • The more recent release 2025102700 exists for Moodle 4.2
  • The more recent release 2025102700 exists for Moodle 4.3
  • The more recent release 2025102700 exists for Moodle 4.4
  • The more recent release 2025102700 exists for Moodle 4.5
  • The more recent release 2025102700 exists for Moodle 5.0

Version control information

Version control system (VCS)
Other...
VCS repository URL
VCS tag
1.0.1

Default installation instructions for plugins of the type Question types

  1. Make sure you have all the required versions.
  2. Download and unpack the module.
  3. Place the folder (eg "myquestiontype") in the "question/type" subdirectory.
  4. Visit http://yoursite.com/admin to finish the installation