Skip to content

Instantly share code, notes, and snippets.

@ad
Created April 23, 2018 11:51
Show Gist options
  • Save ad/1baceee0812d2f95156d244d58dbc2e5 to your computer and use it in GitHub Desktop.
Save ad/1baceee0812d2f95156d244d58dbc2e5 to your computer and use it in GitHub Desktop.
Strip json comments (singleline, multiline), respect base64 //
extension String {
func stripComments() -> String {
// ((\s|,)\/\*[\s\S]*?\*\/)|(( |, ")\/\/.*)
return self.replacingOccurrences(of: "((\\s|,)\\/\\*[\\s\\S]*?\\*\\/)|(( |, \\\")\\/\\/.*)", with: "", options: .regularExpression)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment