Reputation: 933
Cobbling together bits I've come up with this but regex does not like pattern: from SO
struct UAHelpers {
static func isValid(uaString: String) -> Bool {
let regex = try! NSRegularExpression(pattern: ".+?[\/\s][\d.]+")
return (regex.firstMatch(in: uaString, range: uaString.nsrange) != nil)
}
}
which looks ok to me - but no regex expert yet regex.com appears to like it?
Also tried pattern: \(([^(]*)\)
- no joy.
I'm trying to allow user (at own peril) to enter yet provide some parsing.
Upvotes: 0
Views: 314
Reputation: 47896
To represent regex pattern .+?[/\s][\d.]+
as a Swift String, backslashes \
needs to be escaped.
(In Swift String
, /
has no need to be escaped.)
Try using ".+?[/\\s][\\d.]+"
.
Though, I'm not sure if this pattern really extracts what you expect.
Upvotes: 1