I want to remove the vowels from the email id. Which function should I use?
I am trying to find the difference between translate
and replace
in postgresql
but didn't get the exact difference
Using 'str. replace() , we can replace a specific character. If we want to remove that specific character, replace that character with an empty string. The str. replace() method will replace all occurrences of the specific character mentioned.
Using translate(): translate() is another method that can be used to remove a character from a string in Python. translate() returns a string after removing the values passed in the table. Also, remember that to remove a character from a string using translate() you have to replace it with None and not "" .
We can remove part of the string using REPLACE() function. We can use this function if we know the exact character of the string to remove. REMOVE(): This function replaces all occurrences of a substring within a new substring.
translate()
replaces a set of single characters (passed as a string) with another set of characters (also passed as a string), for example:
translate('abcdef', 'ace', 'XYZ') --> 'XbYdZf'
replace()
replaces occurrences of a string of arbitrary length with another string:
replace('abcdef', 'bc', 'FOO') --> 'aFOOdef'
In this case you probably actually want regexp_replace
.
Assuming by "vowel" you mean "Western European (English) language vowel letters" you might write:
SELECT regexp_replace('[email protected]', '[aeiou]', '', 'gi');
the gi
in the fourth argument says "apply this regular expression globally to the whole input string not just to the first match, and make it case insensitive".
Remember that w
and y
are sometimes vowel-sounds, depending on their context, too. You won't be able to handle that with a regexp so it depends on whether or not you care for this purpose.
You're less likely to need to deal with other character sets if you're working with email addresses so a regexp might be OK for this.
In most cases mangling words with regular expressions would not be a good approach, though; for example, Russian in the Cyrillic alphabet uses A Э У О Ы Я Е Ё Ю И
as vowels. Additionally, depending on the language, the same letter in the same script might or might not be a vowel! Keep reading here for more than you ever wanted to know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With