In Swift, you can use the NSRegularExpression
class to find hashtags in a string using regex. Here's an example:
main.swift404 chars11 lines
This code creates a regular expression pattern that matches hashtags (words that begin with a #
symbol) and then finds all occurrences of this pattern in the input string. It then extracts the actual hashtags from the matches and prints them to the console.
Note that this regex pattern matches hashtags only if they are preceded by white space or are at the beginning of the string.
gistlibby LogSnag