I’d like to convert references to usernames such as @me, @you, @them (twitter style) to links. What would be the correct NSRegularExpression pattern for this?
Based on the input from answers below, here’s what I ended up using…
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?<!\\w)@([\\w\\._-]+)?" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *newString = [regex stringByReplacingMatchesInString:stringIn options:0 range:NSMakeRange(0, [stringIn length]) withTemplate:@"<a href='http://mydomain.com/$1'>$0</a>"];
This may not be a perfect match for Twitter, as my own site supports dots, dashes and underlines
@[a-zA-Z0-9_]+should get the job done pretty well.I would recommend throwing some test data in RegExr and fiddling with the regex to match exactly what you need to.