D
D
deleted-mezhevikin2014-05-07 18:10:12
Objective-C
deleted-mezhevikin, 2014-05-07 18:10:12

How to properly compose NSRegularExpression with "or" condition in objective-c?

A page can have one of two links

NSString *pattern1 = @"<a href=\"([^\"]+)\"><span class=\"arr\">&rarr;</span>";
NSString *pattern2 = @"<div class=\"quote more\"><a href=\"([^\"]+)\" class=\"button\">Хочу ещё!</a></div>";

Now I do this, I check the first, then the second, how to do this with one regular expression?
Tried like this, but the whole link is returned and not the href content as in the first case
(<a href=\"([^\"]+)\"><span class=\"arr\">&rarr;</span>)|(<div class=\"quote more\"><a href=\"([^\"]+)\" class=\"button\">Хочу ещё!</a></div>)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gooddy, 2014-05-14
@gooddy

well, the indexes have shifted

(?:<a href=\"([^\"]+)\"><span class=\"arr\">&rarr;</span>)|(?:<div class=\"quote more\"><a href=\"([^\"]+)\" class=\"button\">Хочу ещё!</a></div>)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question