美好的一天。我似乎无法找到如何使用TRegExpr组件来做一个简单的无效字符替换的例子。例如,我有一个字符串='abcdeg3fghijk';并且我想要替换所有无效的字符,如数字'3',那么如何用TRegExpr处理这个字符来替换所有无效字符。我的意图是学习如何使用TRegExpr来构建一个简单的URL清理器/验证器。删除无效的url字符TRegExpr
procedure TForm1.Button3Click(Sender: TObject);
var
RegExp: TRegExpr;
astr:string;
begin
astr:='h"ttp://ww"w.msn."com~~~';
// I want to clean the string to remove all non valid chars
//this is where I am lost
RegExp:=TRegExpr.Create;
try
RegExp.Expression:=RegExpression;
finally
RegExp.Free;
end;
end;
您可能会发现这种有益http://stackoverflow.com/questions/833469/regular-expression-for-url和http:// regexlib.com/Search.aspx?k=URL&AspxAutoDetectCookieSupport=1 或http://mathiasbynens.be/demo/url-regex – bummi
是什么让你觉得'3'是无效的URL字符? – OnTheFly
'3'是为了说明不需要的角色的想法。以上只是一个例子。我不知道如何使用TRegExpr来替换。 – megatr0n