I want to split a string that has brackets in it. I want to make a new array so that:
"aaa(bbb(ccc)ddd)eee(fff)ggg"
becomes:
["aaa", "(bbb(ccc)ddd)", "eee(fff)ggg"]
It should work with "()", "[]:, and "{}", and get the content of the main delimiter. I've been trying to solve it with regex:
all_pos = /^[\\(\\[]*(.*?)[\\.,;:!\\?\\)\\]]*$/
but it's not working. I'm working on a chemistry toolkit, if i enter a name like, propan-2-(methyl)-ol it should give the output in an array as ["propan-2","methyl","ol"]. The number of brackets can be unlimited. And there can be brackets within the bracket. For example:
pentane-2-{ethyl-2-(methane)}-oic acid
So it should split like
["pentane',"2","["ethyl","2","methane"]","oic acid"]
Aucun commentaire:
Enregistrer un commentaire