For example, if a
is in first syllable and same word contains i
, replace a
with ä
.
Barfio -> Bärfio
Foobar -> Foobar
For example, if a
is in first syllable and same word contains i
, replace a
with ä
.
Barfio -> Bärfio
Foobar -> Foobar
newword=word.split("");
if(newword.findIndex(letter=>letter=="a")<3) newword[newword.findIndex(letter=>letter=="a")]="ä";
newword=newword.join("");
http://jsbin.com/jufujumusi/edit?console
Or even more funny:
newword=word.split("").reduce((word,letter,index)=>word+(index<3?{"a":"ä","o":"ø","u":"ů","e":"ë","i":"ï"}[letter]||letter:letter),"");
Analyzing word syllables is pretty complex job and pure regex is hardly a right tool for this. But if we may simplify the requirements to just "a
followed by i
somewhere in the same word", positive lookbehinds is what you're looking for:
a(?=\w*i)