SoftXML
           hdmi splitter | XML Press
Suggest Your Service | Add your website            SoftXMLLib | SoftXMLEcartJS
Archive

SoftXML Archives


 
Sign Up for webmaster bulletin and receive a Free Email Marketing Success Strategies e-book.
Name:
Email:

Hosted Exchange 2010




Wordtracker


Learn ruby                     Go Back To tutorials List

Regular expression example

Regular expression example

def unescapeHTML(string)
   str = string.dup
   str.gsub!(/&(.*?);/) {
      case $1
      when /\Aamp\z/i           then ‘&‘
      when /\Aquot\z/i          then ‘"‘
      when /\Agt\z/i            then ‘>‘
      when /\Alt\z/i            then ‘<‘
      when /\A#(\d+)\z/         then Integer($1).chr
      when /\A#x([0-9a-f]+)\z/i then $1.hex.chr
      end
   }
   str
end

p unescapeHTML("1&lt;2 &amp;&amp; 4&gt;3")       # 1<2 && 4>3
p unescapeHTML("&quot;A&quot; = &#65; = &#x41;") # "A" = A = A
Get RSS for ruby


™SoftXML.   Privacy Statement  |  Link to Us  |  Articles Archive  |  Tutorials Archive  |  Portfolio Archive  |  Products Archive  |  XML Books
^Top