Skip to content

Instantly share code, notes, and snippets.

@Dnomyar
Created March 22, 2015 20:55
Show Gist options
  • Save Dnomyar/80c591d369a43a422a2d to your computer and use it in GitHub Desktop.
Save Dnomyar/80c591d369a43a422a2d to your computer and use it in GitHub Desktop.
Regex : select all spaces not between quotes
Select all spaces not between quotes
Useful for command line parsing
""" +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"""
Scala example :
scala> val input = "hello world \"john doe\""
input: String = hello world "john doe"
scala> input split """ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"""
res0: Array[String] = Array(hello, world, "john doe")
TODO : Remove quotes in the regex ("john doe" -> john doe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment