i need some help in building a regular expression to remove href links with search terms from a long string that i then parse into a web view
an example of the href string : <a href="/search/?search=Huntington">Huntington</a>
i would like to remove everthing but the plain text of the link (just the link itself) but having troubles
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<a href=\"/search/?search=([A-Z][a-z])\"" options:NSRegularExpressionCaseInsensitive error:&error];
any help would be greatly welcomed
Thanks
I think
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<a href=\"[^\"]+\">([^<]+)</a>" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *modifiedString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@"$1"];
should work (I tested the regexp in TextMate but not in XCode).
@Helium3 and @Carl Explain right above and I want to write as corectly and I created this function for delete a href tag from NSString
-(NSString *)deleteAHref:(NSString *)originalString
{
NSError *regexError = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<a href=.*?>(.*?)</a>" options:NSRegularExpressionCaseInsensitive error:®exError];
NSString *modifiedString = [regex stringByReplacingMatchesInString:originalString options:0 range:NSMakeRange(0, [originalString length]) withTemplate:@"$1"];
return modifiedString;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With