You can use the NSRegularExpression class in Swift to find all words ending with "lex" in a string. Here's an example code snippet:
main.swift461 chars18 lines
In this example, we first define our input string and the pattern that we want to match. The pattern is "\b\w+lex\b", which matches any word that ends with "lex".
Next, we create an instance of NSRegularExpression and use it to find all matches in the input string. We loop through each match and extract the corresponding word using the range property of the match.
Finally, we print out each word that matches the pattern. The output of this code snippet will be:
main.swift5 chars2 lines
since that is the only word in the input string that ends with "lex".
gistlibby LogSnag