Jan Kowalski wrote:
> From:
> 
> #header h1 a {
>   display: block;
>   background: url(images/wordpress-logo.png) center left no-repeat;
>   width: 301px;
>   height: 88px;
>   text-indent: -9999px;
>   float: left;
> }
> 
> #header ul li#download a {
>   background: #d54e21 url(images/download-tab-bg.png) bottom left
> repeat-x;
>   color: #fff;
>   -moz-border-radius-topleft: 3px;
>   -khtml-border-top-left-radius: 3px;
>   -webkit-border-top-left-radius: 3px;
>   border-top-left-radius: 3px;
>   -moz-border-radius-topright: 3px;
>   -khtml-border-top-right-radius: 3px;
>   -webkit-border-top-right-radius: 3px;
>   border-top-right-radius: 3px;
>   text-shadow: #b5421c 1px 1px 1px;
> }
> 
> i need each occurence of text enclosed between url(************), for
> this example:
> 
> images/wordpress-logo.png
> images/download-tab-bg.png

str = <<CSS
#header h1 a {
  display: block;
  background: url(images/wordpress-logo.png) center left no-repeat;
  width: 301px;
  height: 88px;
  text-indent: -9999px;
  float: left;
}

#header ul li#download a {
  background: #d54e21 url(images/download-tab-bg.png) bottom left
repeat-x;
  color: #fff;
  -moz-border-radius-topleft: 3px;
  -khtml-border-top-left-radius: 3px;
  -webkit-border-top-left-radius: 3px;
  border-top-left-radius: 3px;
  -moz-border-radius-topright: 3px;
  -khtml-border-top-right-radius: 3px;
  -webkit-border-top-right-radius: 3px;
  border-top-right-radius: 3px;
  text-shadow: #b5421c 1px 1px 1px;
}
CSS

pattern = /url\((.*)\)/ #to match a parenthesis escape it with a '\'

str.each do |line|
  match = line[pattern, 1]  #1 is the parenthesized sub pattern
  if match
    puts match
  end
end

--output:--
images/wordpress-logo.png
images/download-tab-bg.png
-- 
Posted via http://www.ruby-forum.com/.