- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
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)