From: "Sandor Szücs" Date: 2008-08-28T21:01:34+09:00 Subject: Re: Still Query Continues On 27.08.2008, at 08:05, Newb Newb wrote: > Again I have to start from the scratch..From The beginning itself i > got > into problem.Actually my problem is I want to extract the image tag > which contains image file extensions like .jpg .png. You define the last part of your target: ends with .jpg or .png > But currently i m > using this RegEx (//).But it gives me img tags without .jpg or > .png file extensions. That regular expression doesn't match the end: .jpg or .png Think about what your regex will match. Try it yourself with irb. You want to match an url string with a specific ending. Try to match the start, the end and all characters between, without matching characters pre and post of your target. Your string looks like that "test What you want to match is just http://host.domain.tld/path/to/pic.png What characters are allowed in your target? What substrings should be a part of the string you want to match? What characters are the bounces that you don't want to match? Please try to solve the problem yourself. You should learn to think about the problem you want to solve, but I have included one solution. Don't just copy 'n paste a solution. ;) regards, Sandor Szücs -- P.S. What characters are allowed in your target? a-zA-Z0-9:_%\-\.\/ What substrings should be a part of the string you want to match? the last part have to be: \.png or \.jpg or \.gif What characters are the bounces that you don't want to match? In my example above it is ' . Is this character a part of our target? no! here an example: I downloaded the html file of http://rubyforge.org/ irb> s=File.read("RubyForge_ Welcome.html") irb(main):014:0> s.split(' ').select do |w| irb(main):015:1* t= w.match(/[a-zA-Z0-9_:%\-\/\.]*\.(png|jpg|gif)/) irb(main):016:1> puts t if t irb(main):017:1> end http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ header-bg.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ controls-bg.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ tabs-bg.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ inner-tabs-bg.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ active-tab-bg.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ active-inner-tab-bg.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ bottom-fade-bg.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ controls-left.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ header.png /images/lsrc_2008_logo.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ clear.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ clear.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ clear.png http://static.rubyforge.vm.bytemark.co.uk/themes/rubyforge/images/ clear.png