iphone - Extract facebook pages from url [ios] -


my problem minor can't resolve it.

i have 2 facebook url's:

http://www.facebook.com/pages/name_of_page/id_of_page

http://www.facebook.com/name_of_page

and need extract only name using nsregularexpression.

this code:

nsregularexpression* fbregex = [nsregularexpression regularexpressionwithpattern:@"((http|https)://)?([w]{3}\\.)?(facebook\\.com/(pages/)?)" options:0 error:&error]; nsstring *result=[fbregex stringbyreplacingmatchesinstring:string_to_evaluate options:0 range:nsmakerange(0, [string_to_evaluate length]) withtemplate:@""] 

i need remove id of page shown. ideas? thanks.

i've not used nsregularexpressions before, if it's perl-compatible, there couple of ways can want.

this lookbehind method. lookbehinds not capture anything, mark position, match starts character class , ends when runs word boundary.

~(?<=pages/)[-a-z0-9_.]+\b~i 

this forget everything method. \k tells regex engine require pages/ there, forget it. so, has same effect of starting capture @ character class , ending when runs word boundary.

~pages/\k[-a-z0-9_.]+\b~i 

both of these methods give name of page.

here demo


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -