Skip to content Skip to sidebar Skip to footer

Objective-c/swift Regex Matching Across Multliple Lines

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*:\s*'([^']+) This works

Solution 1:

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.

Post a Comment for "Objective-c/swift Regex Matching Across Multliple Lines"