0

我正在尝试在 FPC (Free Pascal) 中使用正则表达式模式 - 更多信息:http ://wiki.freepascal.org/IDE_regular_expressions

然而!我无法确定如何匹配 3 或 4 小写 (az) 字符链的第一次出现(如果有)。

然后我将继续尝试相同的表达式,但这次允许大写和数字组成 3or4 字符链。

帮助赞赏!:]


例如(我尝试过的事情+示例):

s := 'My Name';
// I want the 'ame' portion 1st since there exists a consecutive string of 3 lowercase chars.

// Attempts:    
SplitRegExpr('[[:alnum:]]{3,4}');
SplitRegExpr('[a-z]{3,4}');
SplitRegExpr('[[:alnum:]]{3,4}?');

回应 Ken White,我认为这是正确的链接,不是吗? http://www.gnu-pascal.de/gpc/RegEx.html 我理解这些定义,但我看不到如何正确使用它们来创建(例如我想要做的)匹配模式和返回什么从他们。

4

1 回答 1

0

这是一个提取所有 3 或 4 个小写字符序列的程序。

{$APPTYPE CONSOLE}
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}

uses
  regexpr;

var
  expr: TRegExpr;

begin
  expr := TRegExpr.Create;

  expr.Expression := '[a-z]{3,4}';

  if expr.Exec('My Name is Bunny.') then
    repeat
      WriteLn(expr.Match[0]);
    until not expr.ExecNext;

  expr.Free;
  ReadLn;
end.
于 2015-12-10T09:59:59.003 回答