我曾经使用 HYPERSTR 库进行字符串处理例程。现在我使用较新的Delphi。我需要搜索字符串中的模式,例如旧函数是 function IsMatchEx(const Source, Search:AnsiString; var Start:integer) : Integer;
。实际上我不需要结果值,我只是想知道模式是否与字符串匹配。
我的旧代码(返回 TRUE):
var
StartPos: integer;
FoundPos: integer;
begin
StartPos := 1;
FoundPos := IsMatchEx('abcdef', 'abcd?f', StartPos);
if FoundPos > 0 then
showmessage('match');
end;
我看到Delphi XE有TRegEx,但我还是不明白如何使用它。
这些代码不会返回 TRUE :
if TRegEx.IsMatch('abcdef', 'abcd?f') then
showmessage('match');
使用 MatchesMask
时我也得到了相同的结果.
谢谢。
最佳答案
正则表达式语法不同。 ?和*有不同的含义。请参阅http://www.regular-expressions.info/tutorial.html对正则表达式的精彩介绍。 您可以使用类似 abcd[a-z]f 或 abcd\wf 的语法,甚至其他语法,具体取决于您想要匹配的内容。
关于delphi - 在 Delphi 中使用通配符搜索字符串中的模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5989478/