Lucky Nl wrote:
> Hi
>   I Need small help that how to remove leading   tags
>   My text is:
>      str = "<p>Welcome to ruby &nbsp;&nbsp;</p> <p>&nbsp;&nbsp;</p>"
>    I want result is
>      str = "<p>Welcome to ruby</p>"
> 
> Can anybody help

You mean trailing, rather than leading?

You probably want String#gsub or String#gsub!. For example:

$ irb --simple-prompt
>> str = "<p>Welcome to ruby &nbsp;&nbsp;</p> <p>&nbsp;&nbsp;</p>"
=> "<p>Welcome to ruby &nbsp;&nbsp;</p> <p>&nbsp;&nbsp;</p>"
>> str.gsub!(/(&nbsp;|\s)+/, " ")
=> "<p>Welcome to ruby </p> <p> </p>"
>> 

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/.