getting to decent place now

This commit is contained in:
talksik
2021-12-20 15:41:27 -08:00
parent dec69ecf4e
commit 081ab46a86
9 changed files with 272 additions and 112 deletions
+28
View File
@@ -0,0 +1,28 @@
//
// StringExtension.swift
// nirvana-ios
//
// Created by Arjun Patel on 12/20/21.
//
import Foundation
extension String {
func matchingStrings(regex: String) -> [[String]] {
guard let regex = try? NSRegularExpression(pattern: regex, options: []) else { return [] }
let nsString = self as NSString
let results = regex.matches(in: self, options: [], range: NSMakeRange(0, nsString.length))
return results.map { result in
(0..<result.numberOfRanges).map {
result.range(at: $0).location != NSNotFound
? nsString.substring(with: result.range(at: $0))
: ""
}
}
}
var digits: String {
return components(separatedBy: CharacterSet.decimalDigits.inverted)
.joined()
}
}