Created
January 4, 2018 08:13
-
-
Save geberl/df963947e418908cb0504909961d7680 to your computer and use it in GitHub Desktop.
Finding unescaped spaces in path strings via Regular Expression negative look-behind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import Foundation | |
var path = "/abc/def ghi/jkg\\ lmn/opq" | |
let reEscapedSpaces = "^.*\\\\ .*$" // simple | |
let reUnescapedSpaces = "^.*(?<!\\\\) .*$". // negative look-behind | |
if path.range(of: reUnescapedSpaces, options: .regularExpression) != nil { | |
print("YES match") | |
} else { | |
print("NO match") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment