我正在使用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时,有没有办法去掉前导空格和尾随空格
发布于 2019-01-07 17:18:48
我建议使用相反的方法:将除空格以外的任何字符与\S+正则表达式模式进行匹配:
select regexp_matches(' this is just me ', '\S+', 'g')请参阅online demo。请注意,'g'参数将启用多个匹配。

如有必要,在正则表达式匹配项上使用unnest将数组扩展为一组行。
发布于 2019-01-07 17:17:42
这应该可以做到:
SELECT REGEXP_SPLIT_TO_ARRAY(TRIM(' this is just me '), '\s+');不带参数的TRIM将从字符串remove both leading and trailing whitespace。
发布于 2019-01-07 17:21:39
在将字符串传递给regex_split_to_array函数之前,尝试在字符串上使用trim:
select regexp_split_to_array(trim(' this is just me '), '\s+');https://stackoverflow.com/questions/54071411
复制相似问题