文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>官方的正则表达式组件 RegularExpressions (2) : 子表达式

官方的正则表达式组件 RegularExpressions (2) : 子表达式

时间:2011-03-28  来源:万一


uses RegularExpressions;

const
  pattern = '([A-Z]+)(\d+)'; //其三个子表达式分别是:[A-Z]+\d+  [A-Z]+  \d+
  txt = 'AAA1 BBB2 AA11 BB22 A111 B222 AAAA'; //测试用的目标文本

procedure TForm1.Button1Click(Sender: TObject);
var
  match: TMatch;
  group: TGroup;
  groups: TGroupCollection;
begin
  match := TRegEx.Match(txt, pattern);
  groups := match.Groups;

  Memo1.Clear;
  for group in groups do
  begin
    Memo1.Lines.Add(group.Value); //AAA1/AAA/1
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  match: TMatch;
  group: TGroup;
begin
  Memo1.Clear;
  for match in TRegEx.Matches(txt, pattern) do
  begin
    for group in match.Groups do
    begin
      Memo1.Lines.Add(group.Value);
    end;
    Memo1.Lines.Add('');
  end;
end;
{**************
AA11
AA
11

BB22
BB
22

A111
A
111

B222
B
222
**************}
相关阅读 更多 +
排行榜 更多 +
马里奥赛车世界游戏手机版下载

马里奥赛车世界游戏手机版下载

赛车竞速 下载
无畏契约皮肤开箱器手游下载

无畏契约皮肤开箱器手游下载

休闲益智 下载
旭日之城官方正版下载

旭日之城官方正版下载

策略塔防 下载