Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to remove multiple characters

I can't get rid of trailing ellipsis (multiple characters).
In the context of a Postgres query, this:

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

gives me this:

'if..'  -- quotes mine

Only one of the three periods gets trimmed. How to get rid of the other two? Is there any other special characters that might be trailing in this way?

like image 777
Mike Girard Avatar asked Dec 18 '25 10:12

Mike Girard


1 Answers

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.

like image 187
Erwin Brandstetter Avatar answered Dec 21 '25 02:12

Erwin Brandstetter