0

I have an NSString

@"<a data-poload="/do/usertooltip?id=25203-75736572" data-placement="right">@Some Name</a>".

I want to extract the value between the <a> </a> tag. (i.e. @Some Name) and the elements value (i.e /do/usertooltip?id=25203-75736572, right`) How can I do this in iOS?

eXion
  • 11
  • 3
  • Have you tried using Regular expressions? http://stackoverflow.com/questions/4353834/search-through-nsstring-using-regular-expression – ahmedalkaff Feb 04 '14 at 07:48
  • This may be helpful: "[Parsing HTML on the iPhone](http://stackoverflow.com/questions/405749/parsing-html-on-the-iphone)". – insertusernamehere Feb 04 '14 at 08:38
  • Hi @ahmedalkaff,Yes I've tried with regEx and NSScanner. Here is my regEx pattern. NSString *patter = @"(<)(a)((?:[a-z][a-z]+))(-)((?:[a-z][a-z]+))(=)(\")((?:\\/[\\w\\.\\-]+)+)(\\?)((?:[a-z][a-z]+))(=)(\\d+)(-)(\\d+)(\")(\\s+)((?:[a-z][a-z]+))(-)((?:[a-z][a-z]+)).*?(\".*?\")(>)(@)((?:[a-z][a-z0-9_]*)).*?(<[^>]+>)"; I thing it is wrong with this pattern. – eXion Feb 04 '14 at 08:39
  • Hi @insertusernamehere, I have parsed my HTML text using NSHTMLTextDocumentType. This served my purpose to parse html. But I need to parse above string to get the elements value. – eXion Feb 04 '14 at 08:46

1 Answers1

0

NSString *patter = @"(?i)<a([^>]+)>(.+?)</a>"; Just used this regex and do some string operation extract the desired string. Problem is now solved.

eXion
  • 11
  • 3