无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
查看: 2502|回复: 7
打印 上一主题 下一主题

[分享] 正则提取源码:

[复制链接]
跳转到指定楼层
1#
发表于 2019-11-28 14:46:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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

评分

参与人数 3无忧币 +15 收起 理由
董大 + 5 赞一个!
wanghh + 5 不知如何使用。
hlccfu + 5 很给力!

查看全部评分

2#
发表于 2019-11-28 15:03:03 | 只看该作者
看不懂
五星好评就对了
回复

使用道具 举报

3#
发表于 2019-11-28 18:00:24 | 只看该作者
谢谢楼主的分享,辛苦啦
回复

使用道具 举报

4#
发表于 2019-11-28 18:24:18 | 只看该作者
谢谢楼主的分享,辛苦啦
回复

使用道具 举报

5#
发表于 2019-11-28 19:32:47 | 只看该作者
很赞一个!
回复

使用道具 举报

6#
发表于 2019-11-28 21:18:05 | 只看该作者
佩服佩服,感恩分享!
回复

使用道具 举报

7#
发表于 2019-11-28 22:06:55 来自手机 | 只看该作者
谢谢楼主分享!
回复

使用道具 举报

8#
发表于 2019-11-29 13:10:45 | 只看该作者
看不懂
五星好评就对了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-4-19 23:16

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表