# String match ignoring case in a Predicate

**URL:** <https://forums.swift.org/t/string-match-ignoring-case-in-a-predicate/89129>\
**Category:** Using Swift\
**Tags:** predicate\
**Created:** [August 22, 2026, 4:00pm UTC](https://forums.swift.org/t/string-match-ignoring-case-in-a-predicate/89129 "2026-08-22T16:00:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![somu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@somu](https://forums.swift.org/u/somu)\
**Post date:** [August 22, 2026, 4:00pm UTC](https://forums.swift.org/t/string-match-ignoring-case-in-a-predicate/89129/1 "2026-08-22T16:00:02Z")

</div>

Hi,

# Overview

- I am trying to do a string match ignoring case inside a predicate.
- "slow car" needs to be returned when I search for "Slow Car"

# Problem

- I have tried to use regex but `wholeMatch(of: regex)` is not allowed in a `Predicate`

# Question

- How do I search for a string ignoring a case inside a predicate?

# My attempt

```swift
import Foundation

print("Hello, World!")

struct Car {
    let title: String
    let price: Int
}

let filterText = "Slow CAr"

let regex = Regex<Any>(verbatim: filterText)
    .ignoresCase(true)

let predicate = #Predicate<Car> { car in
    car.title.wholeMatch(of: regex) != nil
}

let c1 = Car(title: "nice fast car", price: 100)
let c2 = Car(title: "slow car", price: 100)
let cars = [c1, c2]

do {
    let filteredCars = try cars.filter(predicate)
    print(filteredCars)
} catch {
    print(error)
}

```

---

<div class="post-metadata">

**Author:** ![Martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Martin](https://forums.swift.org/u/Martin)\
**Post date:** [August 23, 2026, 3:32pm UTC](https://forums.swift.org/t/string-match-ignoring-case-in-a-predicate/89129/2 "2026-08-23T15:32:28Z")

</div>

You can use `caseInsensitiveCompare` (found [here](https://stackoverflow.com/a/79334944/1187415) on Stack Overflow and [here](https://developer.apple.com/forums/thread/733215?answerId=768121022#768121022) in the Apple Developer Forum):

```swift
let orderedSame = ComparisonResult.orderedSame
let predicate = #Predicate<Car> { car in
    car.title.caseInsensitiveCompare(filterText) == orderedSame
}

```

---

<div class="post-metadata">

**Author:** ![somu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@somu](https://forums.swift.org/u/somu)\
**Post date:** [August 23, 2026, 3:35pm UTC](https://forums.swift.org/t/string-match-ignoring-case-in-a-predicate/89129/3 "2026-08-23T15:35:18Z")

</div>

@Martin Thank you so much that is the correct solution.

Declaring the variable `let orderedSame = ComparisonResult.orderedSame` outside the predicate is key, using `ComparisonResult.orderedSame` doesn't work.

Thanks once again.
