[LON-CAPA-users] another regular expression
H. K. Ng
Mon, 22 Aug 2005 15:01:10 -0400
I am trying to construct some general regular expressions and ran into this
$coeff = &random(1,5);
$c_re = '\Q'.$coeff.'\E'.($coeff == 1 ? '?' : '');
$var = '\Qx\E';
$re = '/^\s*$c_re\s*\*?\s*$var\s*$/';
will not work even though it shows as answer
$re = '/^\s*\Q1\E?\s*\*?\s*\Qx\E\s*$/';
when $coeff = 1.
If however, the regular expression is constructed as
$re = '/^\s*\Q$coeff\E'.($coeff == 1 ? '?' : '').'\s*\*?\s*\Qx\E\s*$/';
it works fine. What puzzles me is that the answers displayed for both are
identical. Any ideas?