我正在使用 regexp_split_to_array
通过切割空格来拆分文本,如下所示:
select regexp_split_to_array(' this is just me ', '\s+');
这给出:
{"",this,is,just,me,""}
我想要:
{this,is,just,me}
在应用 regexp_split_to_array
时,有没有办法删除前导和尾随空格?
最佳答案
我建议采用相反的方法:将除空格以外的任何字符与 \S+
正则表达式模式匹配:
select regexp_matches(' this is just me ', '\S+', 'g')
参见 online demo .请注意,'g'
参数将启用多重匹配。
如有必要,在正则表达式匹配上使用 unnest
将数组扩展为一组行。
关于regex - 跳过前导和尾随空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54071411/