如果用的XE,是自带正则库的,用官方的还是比较踏实 正则表达式都是标准的,只是可能有的三方控件会加入自己的一些特性表达式 http://forum.(.*?).netXE测试通过uses RegularExpressions;var Match: TMatch; begin Match := TRegEx.Match('http://forum.csdn.net', 'http://forum.(.*?).net'); if Match.Success then Caption := Match.Groups[1].Value; end;
正则表达式都是标准的,只是可能有的三方控件会加入自己的一些特性表达式
http://forum.(.*?).netXE测试通过uses
RegularExpressions;var
Match: TMatch;
begin
Match := TRegEx.Match('http://forum.csdn.net', 'http://forum.(.*?).net');
if Match.Success then Caption := Match.Groups[1].Value;
end;
http://forum\.(.*?)\.net
.qq. .ifeng. 然后再用字符串函数去掉. 我想直接使用正则直接从网址中得到 csdn qq ifeng 再麻烦一次。
uses
RegExpr;procedure TForm1.btn1Click(Sender: TObject);
var
reg: TRegExpr;
begin
reg := TRegExpr.Create;
reg.InputString := 'www.qq.com';
reg.Expression := '\.(\w+)\.';
if reg.Exec then
begin
Form1.Caption := reg.Match[1];
end;
reg.Free;
end;