WeBWorK Problems

Regex delimiters

Re: Regex delimiters

by Alex Jordan -
Number of replies: 0

In PG, when you have a backslash in your code it will be translated into a double backslash before perl does any interpolation. Your:

$n=~/\d/

becomes:

$n=~/\\d/

and then perl is looking for a
backslash d
not looking for a digit.

It appears that the translator is not doing this when the backslash is inside single quotes.

The reason this happens has to do with backslash also being the LaTeX escape character. So in a math expression, you don't want perl to turn your \frac into whatever \f is followed by rac. The translator makes it \\frac, before perl processes it back to \frac.

And if you really need a backslash, PG lets you use ~~. So your example can be:

$n=~/~~d/

And the translator stage will turn the ~~ into a single backslash before perl processes things further.