I have a regexp to split strings by comma, ignoring commas between single or double quotes, given the following Ruby code:
def separate params
params.split(?!\B('|")[^\"']*),(?![^\"']*('|")\B)
end
It DOES work as intended with the exception of strings that feature special characters like @
or #
Example with expected behavior:
https://regex101.com/r/xB7rQ7/156
"\"search\", placeholder: \"Busca rápida: 1.4 8V, Flex, automático...\", id: \"search_terms\" "
Example with unexpected behavior:
https://regex101.com/r/xB7rQ7/157
"\"search\", placeholder: \"Busca rápida: 1.4 8V, Flex, automático...\", id: \"#search_terms\" "
Note that the only difference is the #
symbol before "search_terms", but the regexp does separate placeholder
from id
only in the first case.
Can anyone shed some light into my regexp so that it works in both cases as expected? Please note this is about a specific case of string splitting that is not covered by another questions.