I would like to split the string by ","
I want to match punctuation, but I don't want to match punctuation in parentheses
Example:
aa(bb,cc),dd,ff
↓(I want to match the '' part)
aa(bb,cc)', 'dd', 'ff
The environment is ruby 2.3
ruby regular-expression
There might be another better way, but I came up with something like this.
"aa(bb,cc), dd,ff".scan(/[^,]*(.*)[^,]*|[^,]+/)
# = > ["aa(bb,cc)", "dd", "ff" ]
© 2024 OneMinuteCode. All rights reserved.