somu
(somu)
1
Hi,
Aim
- I would like to use Swift Regex to find a replace a string.
- I would like it to be a case insensitive search.
Code
var s1 = "THis is a LONG sentence"
s1.replace("this", with: "hello") //I would like it to replace "THis" with "hello"
Questions
- How can achieve this? (Preferably in Swift Regex)
- Or is there a workaround?
cukr
2
var s1 = "THis is a LONG sentence"
s1.replace(try! Regex("this").ignoresCase(), with: "hello")
print(s1) // hello is a LONG sentence
2 Likes
somu
(somu)
3
@cukr Thank you so much!!!
I should have checked the Regex API
Really loving Swift Regex!
1 Like