Search pattern in string using wildcard in Delphi?

扶醉桌前 提交于 2019-12-05 07:27:18

if ? represent a single character:

  if TRegEx.IsMatch('abcdef', 'abcd.f') then
    showmessage('match');

if ? represent any sting:

  if TRegEx.IsMatch('abcdef', 'abcd.*f') then
    showmessage('match');

Don't have XE so haven't tested.

Regular expression syntax is different. ? and * have different meanings. See http://www.regular-expressions.info/tutorial.html for an excellent introduction to regular expressions. You would use something alike abcd[a-z]f or abcd\wf, or even other syntax, depending on what you would like to match.

You can use TMask for wildchar matching:

TMask *m = new TMask("String to check");
bool isMatch = m->Matches("string to*");
delete m;

isMatch = true (C++Builder code is simply translable in Pascal)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!