Hello all,
I am getting a result I do not understand with my regex pattern and I am hoping that someone can explain to me what I am missing. In the code below, "anelope" is yielded for the answer when I would expect it to be "anteeope". I have spent quite a bit of time contemplating how that is the correct answer, but I am just not seeing it as the solution. Can anyone explain to me what I am missing?
My argument for it being "anteeope" is as follows. The pattern matched is the vowel followed by the l, in this case an e. The replacement pattern is to replace the first captured group, which is the vowel, twice. This should yield the double e. The l is dropped.
As to why it should not be anelope, while there is a t in the second part of the pattern, it is not proceeded by a vowel directly in this word, but rather an n, so how is the t then matching the pattern?
Thank you for your time. It is much appreciated.
animals <- c('cat', 'moose', 'impala', 'antelope', 'kiwi bird', 'dog', 'goose', 'hawk')
sub(pattern = '([aeiou]*)[slwt]', replacement = '\\1\\1', x = animals )