regexpostgresql

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?


Solution

  • 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.