1

In the context of a postgres query, this -

lower(regexp_replace('If...', '[^\w\s]', ''))

gives me this -

'if..' (quotes mine)

As you can see, only one of the three periods gets trimmed. Can someone tell me what I must add to my regexp to get rid of the other two or any other special characters that might be trailing in this way?

4

2 回答 2

10

You are probably looking for the fourth, optional parameter of regexp_replace():

SELECT regexp_replace('If...', '[^\w\s]', '', 'g');

g .. for "globally", i.e. replace every match in the string, not just the first.

于 2012-09-05T02:54:41.983 回答
0
SELECT regexp_replace('If, stay real....', '[.]{2,}$', '.', 'g');

{m,} a sequence of m or more matches of the atom.

More than 2 dot in the string will be replaced with one dot.
further reference: https://www.postgresql.org/docs/current/functions-matching.html

于 2021-10-25T11:56:14.773 回答