From: Brian Candler Date: 2010-08-02T18:13:37+09:00 Subject: Re: How to remove leading   from string Lucky Nl wrote: > Hi > I Need small help that how to remove leading   tags > My text is: > str = "

Welcome to ruby   

  

" > I want result is > str = "

Welcome to ruby

" > > Can anybody help You mean trailing, rather than leading? You probably want String#gsub or String#gsub!. For example: $ irb --simple-prompt >> str = "

Welcome to ruby   

  

" => "

Welcome to ruby   

  

" >> str.gsub!(/( |\s)+/, " ") => "

Welcome to ruby

" >> Removing empty paragraphs is left as an exercise. For more information on String and Regexp see http://www.ruby-doc.org/docs/ProgrammingRuby/ However for anything other than the most basic transformations, you are almost certainly better off with a HTML parser like Nokogiri, than chomping HTML with regexps. -- Posted via http://www.ruby-forum.com/.