我的正则表达不承认阿拉伯字符

时间:2016-05-05 16:11:42

标签: php regex preg-replace

我想停止重复一次3次以上的角色,将其转换为3次。

示例:aaaaaaaaaall => aaall

所以,我用英文字符做了,它起作用了:

        // Create a dev token for import
        var devToken = PowerBIToken.CreateDevToken(workspaceCollectionName, workspaceId);
        using (var client = CreateClient(devToken))
        {
            // Import PBIX file from the file stream
            var import = await client.Imports.PostImportWithFileAsync(workspaceCollectionName, workspaceId, fileStream, datasetName);

            // Example of polling the import to check when the import has succeeded.
            while (import.ImportState != "Succeeded" && import.ImportState != "Failed")
            {
                import = await client.Imports.GetImportByIdAsync(workspaceCollectionName, workspaceId, import.Id);
                Console.WriteLine("Checking import state... {0}", import.ImportState);
                Thread.Sleep(1000);
            }

        }

但它对阿拉伯字符不起作用,例如:

$patternReplace = '/(.)\1{3,}/i';
$chaine = preg_replace($patternReplace, "$1$1$1", $chaine, -1 );

thanx求助

1 个答案:

答案 0 :(得分:0)

使用u修饰符:

$patternReplace = '/(.)\1{3,}/iu';
$chaine = preg_replace($patternReplace, "$1$1$1", $chaine, -1 );

来自PHP.net的文档:

  你是(PCRE_UTF8)
  此修饰符打开与Perl不兼容的PCRE的其他功能。模式和主题字符串被视为UTF-8。此修饰符可从Unix上的PHP 4.1.0或更高版本以及win32上的PHP 4.2.3获得。自PHP 4.3.5起,检查模式和主题的UTF-8有效性。无效主题将导致preg_ *函数无匹配;无效模式将触发级别E_WARNING的错误。自PHP 5.3.4起,五个和六个八位字节UTF-8序列被视为无效(分别为PCRE 7.3 2007-08-28);以前那些被认为是有效的UTF-8。