I'm trying to parse the location entries from a .ics file as follows seen in the image below . Normally this works fine even though the only tester I can find is PCRE rather than ICU as I just need to add an extra backslash to any special characters.
However in swift I get the following results:
"^Location" //No Match
"^VERSION" //No Match
"^BEGIN" //Match
"^ :" //Match
Can I get the '^' anchors to function like they do in the PCRE tester?
Code
func testParticipantParsing()
{
//let locationRegex = "^LOCATION:(.*(?:\\n :?.*)*)"
let locationRegex = "LOCATION:(.*(?:\\n :?.*)*)"
var regex : NSRegularExpression! = nil
var resultsArray = [String]()
//Parse for location
do
{
regex = try NSRegularExpression(pattern: locationRegex, options: NSRegularExpressionOptions.init(rawValue: 0))
let nsString = content as NSString
let results = regex.matchesInString(content, options: [], range: NSMakeRange(0, nsString.length))
resultsArray = results.map{ nsString.substringWithRange($0.range) }
}
//Catch errors if regex fails
catch
{
print("invalid regex")
}
//Strip .ics new line tokens
for var result in resultsArray
{
result = result.stringByReplacingOccurrencesOfString("\n :", withString: "")
result = result.stringByReplacingOccurrencesOfString("\n ", withString: "")
print(result)
}
}