In English, there is the fun and simple difference between an
and a
: you use an
when preceding a word starting with a vowel sound, and a
when the word starts with a consonant sound.
For the sake of simplicity in this challenge, an
precedes a word that starts with a vowel (aeiou
), and a
precedes a word that starts with a consonant.
Input
A string comprising only printable ASCII characters, with [?]
appearing in places where you must choose to insert an
or a
. [?]
will always appear before a word. You can assume that the sentence will be grammatically correct and formatted like normal.
Output
The input string with [?]
replaced with the appropriate word (an
or a
). You do have to worry about capitalization!
When to Capitalize
Capitalize a word if it is preceded by no characters (is the first one in the input) or if it is preceded by one of .?!
followed by a space.
Examples
Input: Hello, this is [?] world!
Output: Hello, this is a world!
Input: How about we build [?] big building. It will have [?] orange banana hanging out of [?] window.
Output: How about we build a big building. It will have an orange banana hanging out of a window.
Input: [?] giant en le sky.
Output: A giant en le sky.
Input: [?] yarn ball? [?] big one!
Output: A yarn ball? A big one!
Input: [?] hour ago I met [?] European.
Output: A hour ago I met an European.
Input: Hey sir [Richard], how 'bout [?] cat?
Output: Hey sir [Richard], how 'bout a cat?
This is code-golf, so shortest code in bytes wins!
[?]
and the word? \$\endgroup\$[?] hour ago I met [?] European.
just to make everyone cringe. \$\endgroup\$[?] hour ago I met [?] horse.
\$\endgroup\$