I have a regex that I've been using for a while to highlight a hashtag (eg. #stackoverflow
) or a username/mention (eg. @jeffjohnson
) while a user is typing out text.
Here is how I create that regex:
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(#|@)(\\w+)|(#|@)" options:0 error:&error];
I want to add to this regex pattern so that it will also highlight a URL. So I changed it to the pattern to the following: @"(#|@|http)(\\w+)|(#|@|http)"
This works correctly when they type http
it will become highlighted but when they type a colon (:
) the colon is not highlighted.
If I try adding www
to the regex pattern the same way that I added http
, the same thing happens. www
will highlight correctly but as soon as you type a period (.
) the period will not highlight.
How can I add full URL detection to this regex pattern?