2016-08-21 28 views
-5

Yunqa DiRegExpr中的(?i)令牌用於使匹配大小寫不敏感,但在使用西里爾文本時似乎不起作用。例如:Yunqa DiRegExpr - 西里爾文文本不區分大小寫匹配

\P{Cyrillic}(?i)ново 

應該與大寫的Ново匹配,但它沒有。有沒有一種方法來完成這項工作?

使用DiRegEx Workbench應用程序,我們看到:

enter image description here

我的代碼使用:

if ContainsText(MatchPattern, '(?i)') or 
    ContainsText(MatchPattern, '(?is)') or 
    ContainsText(MatchPattern, '(?si)') then 
     rexp.CompileOptions := [coCaseLess]; 
+2

這是英語的StackOverflow - >看到:HTTP:/ /ru.stackoverflow.com/ –

+1

重要的是要知道你正在使用哪個版本的delphi以及哪個版本的'DiRegExpr'。顯示證明問題的完整代碼也很重要。這很可能是Ansi和Unicode編碼字符串之間的混淆。但是,如果沒有看到您使用的代碼,則很難提供幫助。請參閱:[mcve](或:[Ñрусском](http://ru.stackoverflow.com/help/mcve)) –

+0

@J ...:他或她用英語寫作,對不對? –

回答

0

如果使用UTF8編碼的Unicode字符串必須使用[coUtf8]PCRE_UTF8)編譯選項。匹配成功與此設置。

即:

rexp.CompileOptions := rexp.CompileOptions + [coUtf8]; 

看到的結果,你需要在控制檯裏安裝一個Unicode字體,但這裏是一個演示這樣的例子程序。

program Project1; 
{$APPTYPE CONSOLE} 
uses 
    Windows, DISystemCompat, DIUtils, DIRegEx; 
var 
    RegEx: TDIRegEx16; 
    matched : string; 
begin 
    SetConsoleOutputCP(CP_UTF8); 
    RegEx := TDIPerlRegEx16.Create(nil); 
    try 
    { comment out line below to replicate problem } 
    RegEx.CompileOptions := [coUtf8]; 
    RegEx.SetSubjectStr('Ново'); 
    RegEx.CompileMatchPatternStr('(?i)ново'); 
    if RegEx.Match(0) > 0 then 
     repeat 
     matched := RegEx.MatchedStr; 
     WriteLn('Matched: ', UTF8Encode(matched)); 
     until RegEx.MatchNext < 0 
    else 
     WriteLn('No match.'); 
    finally 
    RegEx.Free; 
    end; 
    ReadLn; 
end. 

你會注意到,包括(?i)的模式,你不需要包含編譯選項[coCaseLess](因爲你也在比賽指定它明確)。

如果你想使用的編譯選項,而不是您可以省略從模式(?i),只是做到這一點,而不是,這也適用:

RegEx.CompileOptions := [coCaseLess, coUtf8]; 
RegEx.SetSubjectStr('Ново'); 
RegEx.CompileMatchPatternStr('ново'); 
相關問題