Search pattern in string using wildcard in Delphi?

后端 未结 3 2203
攒了一身酷
攒了一身酷 2021-02-15 15:34

I used to use HYPERSTR library for string processing routine. Now I use newer Delphi. I need to search a pattern in a string, for example the old function is function IsMa

相关标签:
3条回答
  • 2021-02-15 16:09

    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.

    0 讨论(0)
  • 2021-02-15 16:16

    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)

    0 讨论(0)
  • 2021-02-15 16:19

    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.

    0 讨论(0)
提交回复
热议问题