Does dotless i match I with Turkish locale in caseinsensitive regular expression

Given this code:

import Foundation

extension String {

func matches( _ pattern : String) -> Bool {
    return self.range(of: pattern, options: .regularExpression, locale: Locale(identifier: "tr")) !=  nil 
    }
}

print("f\u{0131}le".matches("(?i)^[a-z]+$")) // returns false
print("f\u{0131}le".matches("(?i)^[a-z,\u{0131}]+$")) // true
print("f\u{0131}le".matches("(?i)^[fıle]+$")) // true
print("FLE".matches("(?i)^[fıle]+$")) // true
print("FILE".matches("(?i)^[fıle]+$")) // false

I would have expected that FILE would match "(?i)[1]+$" that is with a dotless-i given the Turkish locale. What am I missing?


  1. fıle ↩︎

1 Like

It doesn't work any better with

[.regularExpression, .caseInsensitive]

in any case, (?i) is supposed to do the same and does for

print("FLE".matches("(?i)[1]+$")) // true


  1. fıle ↩︎

Then the actual behaviour is at odds with the documentation. That is a bug one way or the other. File one for Foundation: bugs.swift.org.

Until it is fixed, you may be able to work around it by handling ı and/or separately.