Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex an Empty Space in Swift

Tags:

regex

ios

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?

like image 502
thank_you Avatar asked Dec 08 '22 00:12

thank_you


1 Answers

Use two backslashes:

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

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

like image 190
M A Avatar answered Dec 21 '22 05:12

M A