title: Regular expression in ios to extract href url and discard rest of anchor tag?
body: <p>I want to write a url extracting function in objective C. The input text can be anything and may or may not contain html anchor tags.</p>
  
  <p>Consider this:</p>
  
  <pre><code>NSString* input1 = @"This is cool site &lt;a   href="https://abc.com/coolstuff"&gt; Have fun exploring &lt;/a&gt;";
  NSString* input2 = @"This is cool site &lt;a target="_blank" href="https://abc.com/coolstuff"&gt; Must visit &lt;/a&gt;";
  NSString* input3 = @"This is cool site &lt;a href="https://abc.com/coolstuff" target="_blank" &gt; Try now &lt;/a&gt;";
  </code></pre>
  
  <p>I want modified string as <code>"This is cool site https://abc.com/coolstuff</code></p>
  
  <p>Ignoring all text between anchor tag. And need to consider other attributes like _target in anchor tag</p>
  
  <p>I can do something like</p>
  
  <pre><code>static NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"&lt;a\shref=\"(.*?)\"&gt;.*?&lt;/a&gt;" options:NSRegularExpressionCaseInsensitive error:nil];;
  NSString* modifiedString = [regex stringByReplacingMatchesInString:inputString options:0 range:NSMakeRange(0, [inputString length]) withTemplate:@"$1"];
  </code></pre>
  
  <p>Works fine with input1 but fails in other cases.</p>
  
  <p>Thanks</p>