From: ts Date: 2002-10-22T20:09:59+09:00 Subject: Re: newby asks: giving regexps as argument for funvtions >>>>> "T" == T-Online writes: T> i want to pass a regular expression as a parameter to ruby. Tthe following T> code snippet can be made easier but it shows the principle I want to T> understand: In your example you give it a String not a Regexp def findPosRE(str, re) m = re.match(str) m.begin(0) end pos = findPosRE ("hey you behind the wall", /behind/) but it will give an error if the regexp don't match T> def findPosRE(str, re) T> m = %r{re}.match(str) T> return m.begin(0) T> end If you want to give it a String def findPosRE(str, re) m = %r{#{re}}.match(str) m.begin(0) end pos = findPosRE ("hey you behind the wall", "behind") Guy Decoux