By default, the #split
method work as follows:
"id,name,title(first_name,last_name)".split(",")
will give you following output:
["id", "name", "title(first_name", "last_name)"]
But I want something like following:
["id", "name", "title(first_name,last_name)"]
So, I use following regex (from the this answer) using split to get desired output:
"id,name,title(first_name,last_name)".split(/,(?![^(]*\))/)
But, again when I use another string, which is my actual input above, the logic fails. My actual string is:
"id,name,title(first_name,last_name,address(street,pincode(id,code)))"
and it is giving following output:
["id", "name", "title(first_name", "last_name", "address(street", "pincode(id,code)))"]
rather than
["id", "name", "title(first_name,last_name,address(street,pincode(id,code)))"]