The coding challenge here is to “Hipsterfy” a sentence by removing the last vowel in the word as long as is is not also the first letter of a word.
In HipsterPy I will “Hipsterfy” words or sentences in Python. The challenge is eaily done in Regex so can be re-created in any language that has Regex, which is most languages. All that needs to be done is to remove the last vowel in every word in a sentence, the vowel e.g: “A Hipster follows the latest trends and fashions.” goes to “A Hipstr follws th latst trnds and fashins.”.
The solution to this problem is in Regex, the solution can be found on my GitHub and is also shown below.
It is basically just Regex, I will break down the Regex to explain the steps.
The first part
(?i) means case insensitive for the whole Regex. The
([^\s]) means group 1 will be any single character that is not whitespace,
[aeiou] is simply match any vowel.
([^aeiou]*) is get all characters that are not vowels (including no letters at all) after the matched vowel and they will be in group 2, and finally
\b is a word bondary.
For example in
"HipsterPy" you match
"t" being in group 1 and
"rPy" being in group 2. You then substitute the whole match
"terPy" with group 1 and 2 added together
"trPy", this substitution gives you
I have shown how Regex can easily solve a problem with a solution that is easy to understand (so long as you know Regex) and is much shorter than other methods that could be used. I do like Regex as it is very powerful for matching strings in text however it does have its limits and can easily become hard to read for more complex problems.
Subscribe to this blog via RSS.
Adblock (2) Ethics (1) Adverts (2) Images (1) Formats (1) Zeronet (2) P2p (3) Dns (1) Zookos triangle (1) Data (2) Maths (1) Bitcoin (1) Blockchain (1) Svg (1) Python (2) Regex (2) Coding (2) Coding challenge (2) Repl.it (1) Emoji (1)