Home > Software design >  How do I specify matching options in Swift regular expression literal?
How do I specify matching options in Swift regular expression literal?

Time:12-06

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

CodePudding user response:

Swift 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/
  • Related