length replace regexp提取字母数字

查找字符串中逗号出现的次数

https://www.nowcoder.com/practice/e3870bd5d6744109a902db43c105bd50

/*
1、将逗号替换成空白,string长度减去新字段长度,就是逗号个数。
select id,
length(string)-length(replace(string,',','')) as cnt
from strings

2、regexp_replace()提取字段中的字母数字,计算长度差
select id,
length(string)-length(regexp_replace(string,'[^A-Za-z0-9]','')) as cnt
from strings

[^A-Za-z0-9]非字母数字;[A-Za-z0-9]字母数字

3、直接提取逗号计算长度
*/
select id,
length(regexp_replace(string,'[A-Za-z0-9]','')) as cnt
from strings



全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务