title: Swift: how to display image from html source
body: <p>How can I display image from html source in some of sites in swift 2.2?</p>
  
  <p>Actually I don't have any JSON or XML.</p>
  
  <p>The important thing is that I have to use regex.</p>
  
  <p>I tried this:</p>
  
  <pre><code>if htmlContent != nil
  {
      let htmlContent = (item?.htmlContent)! as NSString
      var imageSource = ""
      let rangeOfString = NSMakeRange(0, htmlContent.length)
      let regex = try! NSRegularExpression(pattern: "(&lt;img.*?src=\")(.*?)(\".*?&gt;)", options: [.CaseInsensitive])
      if htmlContent.length &gt; 0
      {
          let match = regex.firstMatchInString(htmlContent as String, options: [.WithTransparentBounds], range: rangeOfString)
          if match != nil
          {
              let imageURL = htmlContent.substringWithRange(match!.rangeAtIndex(2)) as NSString
              print(imageURL)
              if NSString(string: imageURL.lowercaseString).rangeOfString("feedBurner").location == NSNotFound
              {
                  imageSource = imageURL as String
              }
          }
      }
  
      if imageSource != ""
      {
          imgHTMLLoader.setImageWithURL(NSURL(fileURLWithPath: imageSource), placeholderImage: UIImage(named: "placeholder"))
          print("placeholderImage is not! nil")
      }
      else
      {
          imgHTMLLoader.image = UIImage(named: "placeholder")
          print("placeholderImage is nil")
      }
  
  }
  </code></pre>
  
  <p>in this sample(library)... htmlContent always is nil.</p>
  
  <p>this sample , use "Helper library" but it dosn't work...</p>
  
  <p>thanks</p>