PatrickA
(Patrick A)
1
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)+$" that is with a dotless-i given the Turkish locale. What am I missing?
1 Like
PatrickA
(Patrick A)
3
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)+$")) // true
SDGGiesbrecht
(Jeremy David Giesbrecht)
4
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.