SwifterSwift / SwifterSwift

A handy collection of more than 500 native Swift extensions to boost your productivity.
https://swifterswift.com
MIT License
13.8k stars 1.61k forks source link

StringExtensions ~= bug #1196

Open srv7 opened 1 month ago

srv7 commented 1 month ago

Describe the bug

import Foundation

let x = "bjmc1"
switch x {
case "bjmc": print("123")
case "bjmc1": print("345")
default: print("567")
}

345 expected, but 123 was printed. even let x = "bjmc1-asdhjashdb", still 123

image
srv7 commented 1 month ago

related PR: https://github.com/SwifterSwift/SwifterSwift/pull/1113

srv7 commented 1 month ago

seems Duplicated with https://github.com/SwifterSwift/SwifterSwift/issues/1154

srv7 commented 1 month ago

overload your own ~= operator in your project can temporarily solve this

public extension String {
    static func ~= (lhs: String, rhs: String) -> Bool {
        return lhs.range(of: rhs, options: .regularExpression) != nil
    }
}