简体   繁体   中英

Split a string based on Pipe delimiter and except inside brackets ()

I want to split a string by '|'delimiter and exclude those inside the brackets (). I used tokenize function to split by delimiter and have some issue with exclusion part(RegEx format). Please help.

Input: Test|Test1|Test2|(Test3|Test4)|Test5|(Test6)(Test7)|Test8

Output: Test,Test1,Test2,(Test3|Test4),Test5,(Test6)(Test7),Test8

Thanks in advance.

Perhaps the analyze-string function suffices to break up the string, I don't think the single example makes the rules clear but it would be like

analyze-string('Test|Test1|Test2|(Test3|Test4)|Test5|(Test6)(Test7)|Test8','(\([^)]*\))+')/*
/(if (. instance of element(fn:match)) then data() else tokenize(., '\|'))[normalize-space()]

either => string-join(',') that result or use

declare option output:method 'text';
declare option output:item-separator ',';

analyze-string('Test|Test1|Test2|(Test3|Test4)|Test5|(Test6)(Test7)|Test8','(\([^)]*\))+')/*
/(if (. instance of element(fn:match)) then data() else tokenize(., '\|'))[normalize-space()]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM