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 "." So far I can only get it grab everything after the first
forward slash. So far I have:
apache_server_filter.each do |x|
puts x.to_s.scan(/(\/\D+)/)
end
This pulls out: /Documents and Settings/Administrator/Desktop/version
/test_files/ap
Alex Sweps <mailto:lists@ruby-forum.com>
April 11, 2012 10:21 PM
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 "." So far I can only get it grab everything after the first
forward slash. So far I have:
apache_server_filter.each do |x|
puts x.to_s.scan(/(\/\D+)/)
end
This pulls out: /Documents and Settings/Administrator/Desktop/version
/test_files/ap
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.
···
On Thu, Apr 12, 2012 at 4:21 AM, Alex Sweps <lists@ruby-forum.com> 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 "."
File#basename would not work as they are dated and numbered on the live
network. I could have used that to save me time on some old scripts
though >( I got it working using Jeffs regex link. That site has been
bookmarked. Thanks everyone as usual for the fast replies and helpful
info!