Skip to content

Instantly share code, notes, and snippets.

@geberl
Created January 4, 2018 08:13
Show Gist options
  • Save geberl/df963947e418908cb0504909961d7680 to your computer and use it in GitHub Desktop.
Save geberl/df963947e418908cb0504909961d7680 to your computer and use it in GitHub Desktop.
Finding unescaped spaces in path strings via Regular Expression negative look-behind
//: 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