thank_you
thank_you

Reputation: 11107

Regex an Empty Space in Swift

I want to regex a string and see if there is an empty space inside it. Unfortunately due to Swift's use of \ inside double quotes, the code below produces an error.

"space here".rangeOfString("\s", options: .RegularExpressionSearch)

How can I regex to see if an empty space is inside the string?

Upvotes: 4

Views: 9470

Answers (1)

M A
M A

Reputation: 72854

Use two backslashes:

"space here".rangeOfString("\\s", options: .RegularExpressionSearch)

(a single backslash is treated as an escape character).

Upvotes: 14

Related Questions