From: Eric Hodel Date: 2012-06-13T05:39:37+09:00 Subject: Re: Need simple Reg exp On Jun 12, 2012, at 13:24, cyber c. wrote: > i have a string, > > str = "afp://XYZ/a/b/c/d" > > i need to extract "afp://XYZ" . Can anyone suggest a simple reg > expression? URI can do this. $ ruby -ruri -e 'u = URI("afp://XYZ/a/b/c/d"); p u.scheme, u.host' "afp" "XYZ" and: $ ruby -ruri -e 'u = URI("afp://XYZ/a/b/c/d"); puts u + "/"' afp://XYZ/