【问题标题】:How do I specify matching options in Swift regular expression literal?How do I specify matching options in Swift regular expression literal?
【发布时间】:2022-12-02 06:36:37
【问题描述】:

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

【问题讨论】:

    标签: ios swift regex macos


    【解决方案1】:

    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/
    

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 2022-01-04
      • 2022-12-01
      • 2022-12-27
      • 2022-12-26
      • 2022-12-01
      • 2022-12-01
      • 2022-12-01
      • 2022-12-27
      相关资源
      最近更新 更多