Check if string contains regex

 Problem

I want to check if a string contains a specific regular expression.



 Recipe


// String literal
let s = "Hello World"

// Check if it contains one or more 'l's

if s.rangeOfString("l+", options: .RegularExpressionSearch) != nil {
    print("Yes it does")
}
				

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)

 

 Playground