Objective-C/Swift regex matching across multliple lines

后端 未结 1 939
南方客
南方客 2020-12-12 06:14

I have a regular expression originally used in python to extract 2 strings from a scraped HTML page : var\\s+kaynaklar.*?url\\s*:\\s*\\\"([^\\\"]+)\\\"\\s*,\\s*data\\s

相关标签:
1条回答
  • 2020-12-12 06:41

    From your feedback, I see you just need to tell the regex engine to match a newline with a period.

    Use the NSRegularExpressionOptions.DotMatchesLineSeparators option:

    Allow . to match any character, including line separators.


    Available in OS X v10.7 and later.

    As a quicker-to-implement alternative, use an inline (?s) modifier at the beginning of the pattern:

    let regexString = "(?s)var\\s+kaynaklar.*?url\\s*:\\s*\\\"([^\\\"]+)\\\"\\s*,\\s*data\\s*:\\s*'([^']+)"
    

    See the regex demo.

    0 讨论(0)
提交回复
热议问题