regex filter in coderunner template

regex filter in coderunner template

by Mark Stern -
Number of replies: 2

The java class prototype uses a replace filter to modify the student answer. However, it searches for a fixed string. I want to do something similar, but using a regex. What is the easiest way to do that?

In reply to Mark Stern

Re: regex filter in coderunner template

by Richard Lobb -
Twig can't do regular expression matches, so you'd have to use a different approach. 

There may be ways of writing the whole template in Java so that it first modifies the student answer then runs it. But I'm not enough of a Java guru to know how to do that. I would just switch to a Python template that did all the string operations on the student answer in order to build whatever Java code you want to run, then compile and run that code from Python.

If you create a new multilanguage question and customise it, you'll see all the template code there to run a student program in lots of different languages, including Java. So you could start with that and rip out all the other languages. Note that you'd have to change the Ace language field (under Advanced customisation) to just Java to avoid the language drop-down menu appearing.

Alternatively, check out the documentation of the c_via_python question type and change it to run Java instead.

Or some mix of the two.
In reply to Richard Lobb

Re: regex filter in coderunner template

by Mark Stern -
Thanks. I went for the former approach and got it working.