You can use the following regular expression to find all the words ending in "lex" in a string:
main.swift380 chars9 linesIn the above code, we define a string inputString and a regular expression pattern that matches any word that ends with "lex" using the word boundary character \b, zero or more word characters \w*, the characters "lex" literally, and another word boundary character \b.
We then create an instance of NSRegularExpression with the created pattern, and use the matches(in:range:) method to find all matches in the input string. Finally, we extract the matched words from the input string using the Range method and store them in an array words.
gistlibby LogSnag