问题描述
我想用'|'分割一个字符串分隔符并排除括号 () 内的那些。我使用 tokenize 函数按分隔符拆分,并且在排除部分(RegEx 格式)方面存在一些问题。请帮忙。
输入:测试|测试1|测试2|(测试3|测试4)|测试5|(测试6)(测试7)|测试8
输出:Test,Test1,Test2,(Test3|Test4),Test5,(Test6)(Test7),Test8
提前致谢。
解决方法
也许 analyze-string
函数足以分解字符串,我不认为单个示例使规则清晰,但它会像
analyze-string('Test|Test1|Test2|(Test3|Test4)|Test5|(Test6)(Test7)|Test8','(\([^)]*\))+')/*
/(if (. instance of element(fn:match)) then data() else tokenize(.,'\|'))[normalize-space()]
结果或使用=> string-join(',')
declare option output:method 'text';
declare option output:item-separator ',';
analyze-string('Test|Test1|Test2|(Test3|Test4)|Test5|(Test6)(Test7)|Test8','\|'))[normalize-space()]