0

I am doing a body temp regex validation using a regex string. I've tried 2 approach for this validation but both seems to be failing. The regex string itself is correct as I've checked it on an online regex validator

import Foundation

let inputValue = "98.9"

let regexString = "/(96\\.(?:[5-9])$|97$|97(\\.(?:[0-9]))$|98$|98(\\.(?:[0-9]))$|99$|99(\\.(?:[0-5])+$))/"

/// Approach #1

let regexPredicate = NSPredicate(format: "SELF MATCHES %@", regexString)

let regexValidationResult1 = regexPredicate.evaluate(with: inputValue) // Returns false

/// Approach #2

let regex = try! NSRegularExpression(pattern: regexString)

let inputValuerange = NSRange(location: 0, length: inputValue.count)

let regexValidationResult2 = regex.firstMatch(in: inputValue, options: [], range: inputValuerange) // Returns nil
user121095
  • 697
  • 2
  • 6
  • 18

0 Answers0