From: Jeremy Woertink Date: 2007-09-19T07:04:48+09:00 Subject: Re: Regexp help Daniel Lucraft wrote: > Jeremy Woertink wrote: >> What I want to do is determine if a string includes 2 special characters >> a semi-colon and a question mark. > > You don't need regular expressions to do that, try this instead: > > irb> encoding.include? ";" and encoding.include? "?" > => true > > On the other hand, if you want to use regular expressions regardless, > you should notice that String#include? takes a string rather than a > Regexp. > > Note that: > irb> %r{;\?}.to_s > > "(?-mix:;\\?)" > > So > encoding.include?(%r{;\?}.to_s) > > is equivalent to > encoding.include?("(?-mix:;\\?)") > > which is not going to succeed. > > To use a regexp, try: > irb> encoding =~ /(;.*\?)|(\?.*;)/ > => true. > > best > Dan Thanks for the help. I would like to use a regexp becuase I think it will look nicer in the code. I tried your example and got C:\rails_apps\hotswipe>irb irb(main):001:0> require 'config/environment' => true irb(main):002:0> encoding = ";6277200301500269=?" => ";6277200301500269=?" irb(main):003:0> encoding =~ /(;.*\?)|(\?.*;)/ => 0 irb(main):004:0> So what does the 0 mean? 0 matches? If all else fails, I will use the ugly version :) thanks, ~Jeremy -- Posted via http://www.ruby-forum.com/.