如何修改字符串突变的regex代码,使其也适用于重音字母?例如,reges中用于"amor“的字符串突变应该与"āmōr”的字符串突变相同。我只想简单地包括“(?<=aeiouāēīōūăĕĭŏŭ)”这样的重音字母,但这不起作用。
我的代码:
$hyphenation = '~
(?<=[aeiou]) #each syllable contain a vowel
(?:
# Muta cum liquida
( (?:[bcdfgpt]r | [bcfgp] l | ph [lr] | [cpt] h | qu ) [aeiou] x )
|
[bcdfghlmnp-tx]
(?:
# ct goes together
[cp] \K (?=t)
|
# two or more consonants are splitted up
\K (?= [bcdfghlmnp-tx]+ [aeiou])
)
|
# a consonant and a vowel go together
(?:
\K (?= [bcdfghlmnp-t] [aeiou])
|
# "x" goes to the preceding vowel
x \K (?= [a-z] | (*SKIP)(*F) )
)
|
# two vowels are splitted up except ae oe...
\K (?= [aeiou] (?<! ae | oe | au | que | qua | quo | qui ) )
)
~xi';
// hyphention
$result = preg_replace($hyphenation, '-$1', $input);发布于 2016-11-07 20:34:39
在unicode中,重音字母可以用多种方式表示。例如,ā可以是unicode编码点U+0101 (拉丁文小写字母A和马克龙),但也可以是U+0061 (拉丁文小写字母A)和U+0304 (组合马克龙)的组合。(链接)
因此,在以下情况下编写(?<=[aeiouāēīōūăĕĭŏŭ])是正确的:
[eā]+将匹配"ē")。$str = Normalizer::normalize($str);应用于主题字符串。此方法来自英特扩展。您可以在以下链接中找到更多信息:
http://utf8-chartable.de/
http://php.net/manual/en/normalizer.normalize.php
http://php.net/manual/en/reference.pcre.pattern.modifiers.php
http://pcre.org/original/pcre.txt
https://stackoverflow.com/questions/40454224
复制相似问题