Postgresql regexp_replace [英] Postgresql regexp_replace
问题描述
如何用空格替换 1990-2050 中的任何年份?
我可以按如下方式替换任何 4 位数字
select regexp_replace('sdfg 2000', '(\y(\d{4})\y)', '', 'g');
但是我如何另外检查范围?欢迎任何帮助
我发现了一种替代方法来解决您的问题.看看.
您希望替换 1990-2050
中的年份.让我们把这个范围分成
1990-1999
2000-2049
2050
所有三个范围都可以通过以下正则表达式进行匹配.
正则表达式: [1][9][9][0-9]|[2][0][0-4][0-9]|2050代码>
说明:
[1][9][9][0-9]
将匹配从1990
到1999
的年份.[2][0][0-4][0-9]
将匹配从2000
到2049
的年份.2050
将匹配2050
字面|
表示修改.它将检查这三种模式中的任何一种.
How can I replace any year from 1990-2050 with a space ?
I can replace any 4 digit number as follows
select regexp_replace('sdfg 2000', '(\y(\d{4})\y)', '', 'g');
But how additionally I can check the range? Any help are welcome
I have discovered an alternative way to solve your problem. Take a look.
You wish to replace year from 1990-2050
. Let's break that range into
1990-1999
2000-2049
2050
All three ranges can be matched by following regex.
Regex: [1][9][9][0-9]|[2][0][0-4][0-9]|2050
Explanation:
[1][9][9][0-9]
will match years from1990
to1999
.[2][0][0-4][0-9]
will match years from2000
to2049
.2050
will match2050
literally|
means alteration. It will check either of these three patterns.
这篇关于Postgresql regexp_replace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!