我正在使用一种有关拼写特定规则的语言。当单词放在一起时,它们没有空格,但偶尔使用'
或-
到-
区别一个单词开头和另一个单词结尾,在极少数情况下可能发生混淆。如果两个单词的第一个和最后一个字母匹配特定模式,用连字符替换两个单词之间的空格?
我现在与当时的之间的空间中显示的词,如:
The cat caught the mouse.
不过,我需要把空格去掉,如:
Thecatcaughtthemouse.
这些空间之前虽然可以删除,必须考虑关于'
和-
的布局的规则:
首先,如果一个单词的第一个字母(它也是foll OWS另一字)开始于一个元音(a
,a
,á
,à
,ǎ
,ā
,b
,c
,d
,e
,e
,é
,è
,ě
,ē
,i
,i
,í
,ì
,ǐ
,ī
,o
,o
,ó
,ò
,ǒ
,ō
,u
,u
,ú
,ù
,ǔ
,ü
,ǘ
,ǜ
,ǚ
,ǖ
,或ū
),然后用'
替换空间(字之间),例如:
The cat ate the sandwich and the ice cream.
这变为:
Thecat'atethesandwichandthe'icecream.
这不适用于句子开头的单词。
接下来,如果一个单词的最后一个字母开头为 “A”, “U”,或 “U”(a
,a
,á
,à
,ǎ
,ā
,u
,u
,ú
,ù
,ǔ
, ü
,ǘ
,ǜ
,ǚ
,ǖ
,或ū
)和下一个单词在句子开头的 “n”,则替换为-
的空间(字之间),例如:
The people from Australia needed a car to visit the plateau near the river.
这将成为:
Thepeoplefrom'Australia-needed'acartovisittheplateau-neartheriver.
最后,如果一个单词的最后一个字母为“N”和在句子中的下一个单词以“G”开头,结尾,然后替换为-
空间(字与字之间),例如:
The Australian grasshopper was lost in the overgrown grove.
这将成为:
The'Australian-grasshopperwaslostinthe'overgrown-grove.
我怎么能代替匹配这些模式'
和-
单词之间的空格?
而且,如果您需要Unicode处理,可以在[slnunicode](http://files.luaforge.net/releases/sln/slnunicode)中实现支持UTF-8的'gsub'。 – 2012-04-06 08:57:07