demowd.pp 590 B

123456789101112131415161718192021222324252627
  1. {
  2. Program to demonstrate UseUnicodeWordDetection property.
  3. Run this program as
  4. testwd
  5. testwd 1
  6. to see the difference
  7. }
  8. {$mode objfpc}
  9. {$h+}
  10. uses cwstring,uregexpr;
  11. Function ReplaceRegExpr(ARegExpr, AInputStr, AReplaceStr : Unicodestring) : string;
  12. begin
  13. with TRegExpr.Create do
  14. try
  15. UseUnicodeWordDetection:=ParamStr(1)='1';
  16. Expression := ARegExpr;
  17. Result:=Replace (AInputStr, AReplaceStr, True);
  18. finally
  19. Free;
  20. end;
  21. end;
  22. begin
  23. Writeln(ReplaceRegExpr('\w+', UTF8Decode('test слово ŕáćéí ϸϬϛ ュユョ'), '<$0>'));
  24. end.