From: Joel VanderWerf Date: 2009-06-05T05:14:27+09:00 Subject: Re: Regular expressions: Find part of a string Jermaine wrote: > Hello Everyone, > > I'm quite new to regular expressions, and I'm looking for a way to > find the first 3 letters in a string. > > So let's say I have the following string: "foobar", I want to know > what the first three letters of this string is (in this case it's > foo). > > What is the regex to make this happen? > > Thanks in advance. p "foobar"[/.../] # simplest p "foobar"[/\A.../] # \A anchors to beginning of string, which is # same as above for this regex p "foobar"[/.{3,3}/] # accepts between 3 and 3 chars -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407