转载自:http://www.cnblogs.com/Stwo/archive/2011/08/29/2158260.html
有一网友问了一个有关正则的问题,即取出以单词begin开头和单词end结尾之间的字符串,很感兴趣便动手试下,可试了很多次效果不是太理想,今天简单的实现了,代码如下:
unit
Unit1;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,RegularExpressions,StdCtrls;
type
TForm1 =
class
(TForm)
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
Label1: TLabel;
Label2: TLabel;
procedure
Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end
;
var
Form1: TForm1;
implementation
{$R *.dfm}
TForm1
.
Button1Click(Sender: TObject);
var
@H_301_130@
Regex: TRegex;
begin
Regex := TRegex
Create(Edit1
Text,[roIgnoreCase]);
try
if
Regex
Match(Memo1
Text).Success
then
begin
ShowMessage(Regex
Text).Value);
;
finally
;
;
.
|
(注:开发环境XE)
(
)
原文链接:https://www.f2er.com/regex/361984.html