From: Jeff Schoolcraft Date: 2008-04-15T22:42:24+09:00 Subject: Re: Reg Exp ------=_Part_1361_30421753.1208266560377 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I don't think you'll be able to do what you want with just a regex pattern. The closest you could get is negative lookahead. You'd have to pull out th= e first character and use negative lookahead for the rest, it will probably only work for simple strings. irb(main):029:0> a =3D "Hello World" =3D> "Hello World" irb(main):030:0> a =3D~ /h(?!ello)/i =3D> nil irb(main):031:0> b =3D "Hel l o world" =3D> "Hel l o world" irb(main):032:0> b =3D~ /h(?!ello)/i =3D> 0 On Tue, Apr 15, 2008 at 9:17 AM, Dipesh Batheja wrote: > Problem is i have function, which takes a regex as the parameter. I want > to pass this regex in such a way that the function returns false if the > string is matched and true if it isn't. I want the regex itself specify > that if it matches the given string then it is false otherwise true. > > Jes=FAs Gabriel y Gal=E1n wrote: > > On Tue, Apr 15, 2008 at 2:59 PM, Dipesh Batheja > > wrote: > >> Can somebody hep me with a very simple regular expression. I want to > >> write an regex which if matches a specific string should return false= . > >> for example: > >> if i have string "Hello world", and i want to say, if you find "hello= " > >> in this string then return false. Can someone explain how to write > this? > > > > Simple approach: > > > > irb(main):007:0> a =3D "hello world" > > =3D> "hello world" > > irb(main):008:0> !(a =3D~ /hello/) > > =3D> false > > irb(main):009:0> !(a =3D~ /asdfsdf/) > > =3D> true > > > > Jesus. > > -- > Posted via http://www.ruby-forum.com/. > > --=20 Jeff Schoolcraft http://thequeue.net/blog/ Microsoft MVP ------=_Part_1361_30421753.1208266560377--