Last active
February 15, 2018 23:38
-
-
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
This file contains hidden or 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
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