Skip to content

Instantly share code, notes, and snippets.

@ErvalhouS
Last active February 15, 2018 23:38
Show Gist options
  • Save ErvalhouS/5a647c9906335907572dcf6b045b7e21 to your computer and use it in GitHub Desktop.
Save ErvalhouS/5a647c9906335907572dcf6b045b7e21 to your computer and use it in GitHub Desktop.
This one line def will separate the string by commas, unless the commas are inside simple OR double quotes using only Ruby's `split` and regexp
module CommaSeparator
def separate params
params.split(/(?!\B\b('|")[^\"']*),(?![^\"']*('|")\B\b)/)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment