From: "Jesús Gabriel y Galán" Date: 2012-04-12T16:21:45+09:00 Subject: Re: Regular expression help On Thu, Apr 12, 2012 at 4:21 AM, Alex Sweps wrote: > Hello all > > I have written a script to search the current directories and grab the > file path for a set of filtered files. Example of what it returns: > c:/Documents and Settings/Administrator/Desktop/version3/test_files/apserver1.int-APACHE.gz > c:/Documents and > Settings/Administrator/Desktop/version3/test_files/apserver2.int-APACHE.gz > c:/Documents and > Settings/Administrator/Desktop/version3/test_files/apserver3.int-APACHE.gz > > What I am trying to do is extract only the server names. So apserver1, > apserver2 and apserver3. I need a regular expression that will grab > everything after the last forward slash and then the text before the > first "." First, I'd use File#basename to get the filename. Then you can use the String#[] method with a regex that gets everything up to the first point, like this: 1.9.2p290 :009 > s = "c:/Documents and Settings/Administrator/Desktop/version3/test_files/apserver1.int-APACHE.gz" => "c:/Documents and Settings/Administrator/Desktop/version3/test_files/apserver1.int-APACHE.gz" 1.9.2p290 :010 > File.basename(s)[/[^.]*/] => "apserver1" Jesus.