I'm looking for the best (and simple) way (Shell, Javascript, AppleScript, RegEx…) to convert and replace accented and special characters (diacritics) from a string (Clipboard, Variable,…)
Examples:
Replace ā, á, ǎ, and à with a.
Replace ē, é, ě, and è with e.
Replace ī, í, ǐ, and ì with i.
Replace ō, ó, ǒ, and ò with o.
Replace ū, ú, ǔ, and ù with u.
Etc.
For now, I'm using a sequence of "Search and Replace" actions with RegEx but I would like to simplify the process.
The structure of the problem is, of course, given by the fact that there is no formally definable relationship between the incoming characters with diacritics and the outgoing similar characters without diacritics.
That points to two quite large sets of regexes – one for the lower-case targets and and for the upper.
A lot of work ... and someone is bound to have done it before. On macOS you should, I think, find that you have command line access to iconv which is a bundling of such conversions.
In terminal.app or iTerm.app etc, you could start by entering:
man iconv
See, for example, under the //TRANSLIT option here:
The three solutions seem to work perfectly. But, sorry to @ComplexPoint and @CJK, I'll probably use the one from @ccstone. This JavaScript function is perfect to me. Short and understandable! I will bookmark the two others though.