Aleksandr Medvedev
Aleksandr Medvedev

Reputation: 8978

How do I specify matching options in Swift regular expression literal?

With new literal syntax for Swift regular expressions it remains unclear how can I add search flags to it?

let regex = /^foo/mi // Cannot find 'mi' in scope error

Upvotes: 1

Views: 175

Answers (1)

Aleksandr Medvedev
Aleksandr Medvedev

Reputation: 8978

Swift regex literal parser doesn't have expression-wide matching options, but you can specify any options inline at very beginning of the pattern to achieve the same effect:

let regex = /(?mi)^foo/

Upvotes: 4

Related Questions