Is there a simple way in Swift 5.7 to get a regular expression that ignores diacritics when matching?

Viewed 82

Swift 5.7 introduces a lot of improvements for regular expressions, including a .ignoresCase() function to ignore casing when matching.

"Lorem IPSUM dolor.".contains(/ipsum/.ignoresCase()) // true

I didn't find any equivalent ignoresDiacritic() function. Do you know why? Is it recommended to remove the diacritic from the string first? And if so, which of these two methods is better?

"Lorem ÏPSÛM dolor."
    .applyingTransform(.stripDiacritics, reverse: false)!
    .contains(/ipsum/.ignoresCase()) // true

"Lorem ÏPSÛM dolor."
    .folding(options: .diacriticInsensitive, locale: .current)
    .contains(/ipsum/.ignoresCase()) // true
0 Answers
Related