I try to include \' symbol to Regular Expressions
I use this function
func matches(for regex: String, in text: String) -> [String] {
do {
I guess that what you really want is this:
"['0-9a-zA-Z]+"
Note that I have removed the ^
(text start) and $
(text end) characters because then your whole text would have to match.
I have merged the groups because otherwise you would not match the text as a whole word. You would get separate apostrophe and then the word.
I have changed the ‘
character into the proper '
character. The automatic conversion from the simple apostrophe is caused by iOS 11 Smart Punctuation. You can turn it off on an input using:
input.smartQuotesType = .no
See https://developer.apple.com/documentation/uikit/uitextinputtraits/2865931-smartquotestype