I have a image url like this
From this url i need to extract only the picture name using regular
Expressions.
That is I Want to Extract like this => Davis-Love-III.jpg.
Any Advices
I have a image url like this
From this url i need to extract only the picture name using regular
Expressions.
That is I Want to Extract like this => Davis-Love-III.jpg.
Any Advices
2008/8/25 Newb N. [email protected]
I have a image url like this
From this url i need to extract only the picture name using regular
Expressions.
That is I Want to Extract like this => Davis-Love-III.jpg.
Any Advices
http://www.ingolfwetrust.com/golf-central/content/binary/Davis-Love-III.jpg"
filename = url.scan(/[^/]+/).last
This looks for all sections of the string that do not contain a slash
and
picks the last one.
There are probably dozens of ways to do this. Here is a simple way that
does use regular expressions:
url.split("/").last
url = "
http://www.ingolfwetrust.com/golf-central/content/binary/Davis-Love-III.jpg"
filename = url.scan(/[^/]+/).lastThis looks for all sections of the string that do not contain a slash
and
picks the last one.
Thanks for the reply…it works but my url is like this
so it gives me only this
aggbug.ashx?id=56f9e33a-6333-4daf-b4e1-137ddc051adf">
Pls Help me on this
What do you want to do with
aggbug.ashx?id=56f9e33a-6333-4daf-b4e1-137ddc051adf ? Are you using it ?
If not , for the rest of the pictures , you could be calling
File.basename on them and get the last part only . For example , on
http://www.ingolfwetrust.com/golf-central/content/binary/Davis-Love-III.jpg
you will receive Davis-Love-III.jpg .
sorry yar …Nothing Work On That.I get nil value
Any ways i used this expression to extract the imgage url =>
(/<img.*?>/)
It has given me image url.
But I want to get all the url’s based on file extensions like jpg and
png…
That Is… if it contains image file extension,Only those image urls
has to fetched
Help Me
Thanks for the reply…it works but my url is like this
so it gives me only this
aggbug.ashx?id=56f9e33a-6333-4daf-b4e1-137ddc051adf">
Pls Help me on this
What do you want to do with
aggbug.ashx?id=56f9e33a-6333-4daf-b4e1-137ddc051adf ? Are you using it ?
If not , for the rest of the pictures , you could be calling
File.basename on them and get the last part only . For example , on
http://www.ingolfwetrust.com/golf-central/content/binary/Davis-Love-III.jpg
you will receive Davis-Love-III.jpg .
#!/usr/bin/ruby
require ‘rubygems’
require ‘hpricot’
ext = %w( .jpg .png .gif … )
Hpricot(DATA.read).search(“img”) do |img|
name = File.basename(img.attributes[‘src’])
puts name if ext.include?(File.extname(name))
end
END
[~]$ blah
#=>
foo.jpg
image.jpg
On Mon, Aug 25, 2008 at 2:13 PM, Newb N. [email protected] wrote:
Any ways i used this expression to extract the imgage url =>
(/<img.*?>/)
It has given me image url.
But I want to get all the url’s based on file extensions like jpg and
png…
That Is… if it contains image file extension,Only those image urls
has to fetched
Another way to extract the URL and get only the path:
require ‘uri’
tag = ‘’
File.basename(URI.split(URI.extract(b)[0])[5])
=> “aggbug.ashx”
Then you can check with File.extname to check for the extensions you
want, as others have shown.
Hope this gives you other ideas,
Jesus.
Hi all …
I redefine my Question now…i want to get all the image url which has
.jpg .png file extensions using regular expressions …
Any Advices…
#!/usr/bin/ruby
require ‘rubygems’
require ‘hpricot’
ext = %w( .jpg .png .gif … )
Hpricot(DATA.read).search(“img”) do |img|
name = File.basename(img.attributes[‘src’])
puts name if ext.include?(File.extname(name))
end
END
[~]$ blah
Newb N. wrote:
url = "
http://www.ingolfwetrust.com/golf-central/content/binary/Davis-Love-III.jpg"
filename = url.scan(/[^/]+/).lastThis looks for all sections of the string that do not contain a slash
and
picks the last one.Thanks for the reply…it works but my url is like this
so it gives me only this
aggbug.ashx?id=56f9e33a-6333-4daf-b4e1-137ddc051adf">
Pls Help me on this
Althow it is not the most genius one
url.split(“/”).last.gsub(/"|>/,‘’)
by
TheR
Newb N. wrote:
my Question is…i want to get all the image url which has .jpg .png
file extensions using regular expressions …
How did you do with the pattern we already suggested, with “.*?.jpg” in
it?
Can you run another pass with “.*?.png” too?
my Question is…i want to get all the image url which has .jpg .png
file extensions using regular expressions …
Any Advices…
Phlip wrote:
Newb N. wrote:
my Question is…i want to get all the image url which has .jpg .png
file extensions using regular expressions …How did you do with the pattern we already suggested, with “.*?.jpg” in
it?Can you run another pass with “.*?.png” too?
could you pls give me the full regular expressions to do that?
Phlip wrote:
Can you run another pass with “.*?.png” too?
could you pls give me the full regular expressions to do that?
What happened to the ones people here posted?
hi…
I Got it work.Thank u for taking time to reply
Can you run another pass with “.*?.png” too?
could you pls give me the full regular expressions to do that?
What happened to the ones people here posted?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs