[LON-CAPA-users] Regular expressions in string response
Tue, 1 May 2007 09:14:03 -0400
On May 1, 2007, at 8:33 AM, Robert_Brewington@er.monroe.edu wrote:
> I am trying to set up a string response question that takes the
> answer and removes blanks before comparing to the correct answer.
> someone has a code snippet that does this?
> Student input:
> a b c
> I want to match to
\s* matches any number of spaces, including zero:
/^(a\s*b\s*c|a\s*c\s* ...) ...
> (Incidentally, what does the "b" do in this expression?)
Matches a word boundary, and is not appropriate if you want to
consider spaces. Your whole expression would be
> I am looking for something like the vi command to remove spaces:
> s/ //g
Rather than removing them, I would match them.
As the saying goes:
You have a problem, and think: "Oh, I'll just use a regular
expression!" - now you have two problems.
But seriously, I love regular expressions.