Question Authors' Forum

Regular expression flavor?

 
Picture of Miguel Rubio
Regular expression flavor?
by Miguel Rubio - Sunday, 27 November 2016, 5:28 AM
 

Hello,

First of all I would like to thank all the people involved in this project. We are using it in our CS1 course and finding it very useful.

We are using the regular expression grading and we would like to know the underlying engine. After browsing the code we believe it is a PHP-style PERL engine but would like to confirm it.

Miguel Ángel Rubio

Department of Computer Science

University of Granada

Picture of Richard Lobb
Re: Regular expression flavor?
by Richard Lobb - Monday, 28 November 2016, 11:31 AM
 

Hi Miguel

Good to know you're finding CodeRunner useful.

The two relevant PHP lines are

        $regex = '/' . str_replace('/', '\/', rtrim($testcase->expected)) . '/ms';
        $iscorrect = preg_match($regex, $output);

So matching is done by a call to PHP's "PERL regular expression match" function - essentially the entire student output is searched for any embedded occurrence of the given regular expression. The regular expression is that supplied in the question authoring form ($testcase->expected), trimmed and wrapped in slashes ('/'s) after escaping any existing slashes. The 'ms' modifiers are PCRE_MULTILINE and PCRE_DOTALL, so that '^' and '$' match at the start and end of lines, rather than just at the start and end of the entire output string and '.' matches all characters including newlines.

Richard

Picture of Miguel Rubio
Re: Regular expression flavor?
by Miguel Rubio - Tuesday, 29 November 2016, 5:13 AM
 

That was what I needed, Thanks.

Miguel