delphi XE8中的正则表达式提取日语(平假名,片假名,汉字)  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi XE8中的正则表达式提取日语(平假名,片假名,汉字)


使用Delphi XE8中的正则表达式提取日语(平假名,片假名,汉字)

您可以在正则表达式中使用以下字符:

平假名... \ p {平假名} 
片假名... \ p {假名} 
汉字... \ p {汉}

使用此提取平假名,片假名和汉字。

program Project1;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  System.SysUtils, RegularExpressions;

const
  Target = '1あ2い3漢a字bカcナ';
  Pattern = '[\p{Hiragana}|\p{Katakana}|\p{Han}]';

var
  match: TMatch;
  matches: TMatchCollection;
begin
  matches := TRegEx.matches(Target, Pattern);
  for match in matches do
    WriteLn(Format('%s (%d, %d)', [match.Value, match.Index, match.Length]));
end.
执行结果

あ (2, 1)
い (4, 1)
漢 (6, 1)
字 (8, 1)
カ (10, 1)
ナ (12, 1)

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.032302856445312 seconds