From: Robert Klemme Date: 2009-09-08T01:25:11+09:00 Subject: Re: How to convert a "normal" searchstring into regexp On 07.09.2009 18:12, Kioko -- wrote: > Robert Klemme wrote: >> this seems to do the trick: >> http://pastie.org/608326 >> I haven't tested it much though... > > Thanks, but unfurtunatly it seems to not work correctly. > As I tested it with my example string "my.li??le.searchstri*g\?" the > result was >> "/^..my\\.li.*le\\.searchstri\\?g$/". > (to compare it easier, it should be something like: >> "/^my\.li..le\.searchstri.*g\?$/" > > robert, thank you too but also with your script I get an error if I try > to run it: >> undefined (?...) sequence: /(? > As I'm new to ruby I don't know if it's just me... you tried it too and > didn't get an error. > My version: "ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]" > installed over apt (ubuntu) It's the Ruby version. You need Oniguruma which is default in 1.9 and I believe it is just optional in 1.8.7. I tested with 1.9.1. Sorry for the confusion. You can probably make it work with something like this # untested class String def to_glob Regexp.new(gsub(%r{(? "\\.", "*" => ".*", "?" => "." } end > However, thank you very much for your replies and your time. You're welcome! Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/