I have a string "Today is Monday and date is 12 januari, 2019". The month in the date format is displayed by locale. I am trying to figure out regex in swift to check if the string contains date and if it does get only date from the string.
I have tried different regex's It seems like my regex is wrong but I can't figure out how to handle the localized month in the date.
func extractDOB(memberInfo: String) -> [String] {
var toReturn = [String]()
let dobRegEx = "[0-9]{2}/s[a-zA-Z]/s[0-9]{4}"
do {
let regex = try NSRegularExpression(pattern: dobRegEx)
let nsString = memberInfo as NSString
let results = regex.matches(in: memberInfo, range:
NSRange(location: 0, length: nsString.length))
if results.count != 0 {
for result in results {
let matchRange = result.range
toReturn.append(nsString.substring(with:
matchRange))
print(toReturn)
}
}
} catch let error as NSError {
print("invalid regex: \(error.localizedDescription)")
}
return toReturn
}
String: This is monday and date is 12 januari, 2019 ExpectedOutput: 12 januari, 2019