[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: folding double vowels?
- From: Sean Conner <sean@...>
- Date: Wed, 22 May 2013 16:11:10 -0400
It was thus said that the Great Petite Abeille once stated:
> Hello,
>
> Brain freeze of the day… what would be a reasonable Lua string pattern to fold double vowels into one?
>
> E.g.:
>
> ao -> a
> ii -> i
> ue -> u
>
> etc…
>
> Got the following at the moment:
>
> print( ( 'aaaa aaa aa a aaaaa' ):gsub( '([aeiou]?)([aeiou]?)', '%1' ))
>
> > aa aa a a aaa
>
> Is there a more straightforward way?
lpeg = require "lpeg"
Cf = lpeg.Cf
Cc = lpeg.Cc
C = lpeg.C
P = lpeg.P
pattern = Cf(
Cc""
* (P"ao" / "a" + P"ii" / "i" + P"ue" / "u" + C(P(1)))^1,
function(a,b) return a .. b end
)
print(pattern:match("ao ii ue"))
-spc