无忧启动论坛

标题: 正则提取源码: [打印本页]

作者: tt911    时间: 2019-11-28 14:46
标题: 正则提取源码:
本帖最后由 tt911 于 2019-11-28 14:58 编辑

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    ListBox1: TListBox;
    Edit1: TEdit;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure hotykey(var msg: TMessage); message WM_HOTKEY;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  id1: Integer;         //id1 ctrl+shift+r

implementation

{$R *.dfm}
uses
  TLHelp32, PsAPI, Clipbrd, RegularExpressions;

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
  match: TMatch;
begin
  ListBox1.Clear;
  for I := 0 to Memo1.Lines.Count - 1 do
  begin
     //ShowMessage(Memo1.Lines[I]);
    match := TRegEx.match(Memo1.Lines[I], '(?<=模块=).*(?=\..*)');
    if match.Success then
    begin
      //ShowMessage(match.Value);
      ListBox1.Items.Add(match.Value + #13#10);
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  match: TMatch;
begin
  match := TRegEx.match(Edit1.Text, '(?<=模块=).*(?=\..*)');
  if match.Success then
  begin
    ShowMessage(match.Value);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  id1 := GlobalAddAtom('hotkey1');
  RegisterHotKey(handle, id1, MOD_CONTROL + MOD_SHIFT, 82);                          //ctrl+shift+r
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey(handle, id1);
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  ShowMessage(ListBox1.Items[ListBox1.ItemIndex] + #13#10 + '已复制到剪贴板');
  Clipboard.AsText := ListBox1.Items[ListBox1.ItemIndex];
end;

procedure TForm1.hotykey(var msg: TMessage);
var
  h: HWND;
  pid: Cardinal;
  pHandle: THandle;
  buf: array[0..MAX_PATH] of Char;
  SelectedIndex: Integer;
begin
  if (GetAsyncKeyState(VK_CONTROL) < 0) and (GetAsyncKeyState(VK_SHIFT) < 0) and (GetAsyncKeyState(Ord('R')) < 0) then        //Ctrl+Shift+R
  begin
    ListBox1.Selected[ListBox1.ItemIndex + 1] := True;
//ShowMessage(ListBox1.Items[ListBox1.ItemIndex + 1] + #13#10 + '已复制到剪贴板');
    Clipboard.AsText := ListBox1.Items[ListBox1.ItemIndex];
  end;
end;

end.

delphi正则提取源码.rar

8.1 KB, 下载次数: 18, 下载积分: 无忧币 -2


作者: hlccfu    时间: 2019-11-28 15:03
看不懂
五星好评就对了
作者: 董大    时间: 2019-11-28 18:00
谢谢楼主的分享,辛苦啦
作者: yynq    时间: 2019-11-28 18:24
谢谢楼主的分享,辛苦啦
作者: snakegao    时间: 2019-11-28 19:32
很赞一个!
作者: praijna    时间: 2019-11-28 21:18
佩服佩服,感恩分享!
作者: dlwfdlikuan    时间: 2019-11-28 22:06
谢谢楼主分享!
作者: 心好累夜独醉    时间: 2019-11-29 13:10
看不懂
五星好评就对了




欢迎光临 无忧启动论坛 (http://bbs.wuyou.net/) Powered by Discuz! X3.3