如何在PostgreSQL的字符串中查找特定字符的第一次和最后一次出现 [英] How to find the first and last occurrences of a specific character inside a string in PostgreSQL

查看:975
本文介绍了如何在PostgreSQL的字符串中查找特定字符的第一次和最后一次出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查找字符串中特定字符的第一次和最后一次出现.例如,考虑一个名为"2010-####-3434"的字符串,并假设要搜索的字符为#".字符串中哈希的第一个出现在第6个位置,最后一个出现在第9个位置.

I want to find the first and the last occurrences of a specific character inside a string. As an example, consider a string named "2010-####-3434", and suppose the character to be searched for is "#". The first occurrence of hash inside the string is at 6-th position, and the last occurrence is at 9-th position.

推荐答案

我不知道该怎么做,但是像regexp_matchesregexp_replaceregexp_split_to_array这样的正则表达式函数可能是解决您的问题.

I do not know how to do that, but the regular expression functions like regexp_matches, regexp_replace, and regexp_split_to_array may be an alternative route to solving your problem.

这篇关于如何在PostgreSQL的字符串中查找特定字符的第一次和最后一次出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆