delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

  pattern = "^#{r1}#{r2}#{r3}#{r4}$"
  roman = Regexp.new(pattern)
  end
How would I go about testing this program, is there anything I need to add, to proceed from here?
Any help would be much appreciated,
Thanks,
Dan


Hi, I just need a little help with a problem Iam doing, I think I've almost figured it out I just need some help finishing it. Ive been asked to write a regular expression to see whether a string represents a valid roman numeral. So I did that pretty much..
I=1
V=5
X=10
L=50
C=100
D=500
M=1000
  r1 = "M{0,1}"
  r2 = "(CM|CD|D?C{0,3})"
  r3  = "(XC|XL|L?X{0,3})"
  r4 = "(IX|IV|V?I{0,3})"
  pattern = "^#{r1}#{r2}#{r3}#{r4}$"
  roman = Regexp.new(pattern)
  end
How would I go about testing this program, is there anything I need to add, to proceed from here?
Any help would be much appreciated,
Thanks,
Dan
Author Hot threads

TOP

You should try to look at the output of roman.inspect() or roman.to_yaml() will give you an idea of what the object that Regexp.new() has returned.  That may help you to proceed.

TOP

I forgot to include that in order to test your example, you'll have to do:
Code:
  1. numeral = "XVIII"
  2. roman.match(numeral)
Copy Code
Also, you can evaluate a regexp using the =~ operator like this:
Code:
  1. "XVIII" =~ /romanRegexp/
Copy Code
the results of the match are available in the global variables $1, $2, $3, ...
Have a look at the documentation



  pattern = "^#{r1}#{r2}#{r3}#{r4}$"
  roman = Regexp.new(pattern)
  end
How would I go about testing this program, is there anything I need to add, to proceed from here?
Any help would be much appreciated,
Thanks,
Dan

TOP

Back Forum