php string matching with wildcard *?

后端 未结 6 1012
悲&欢浪女
悲&欢浪女 2021-02-06 23:18

I want to give the possibility to match string with wildcard *.

Example

$mystring = \'dir/folder1/file\';
$pattern = \'dir/*/file\';

string         


        
6条回答
  •  长发绾君心
    2021-02-06 23:27

    .+?
    

    Causes non-greedy matching for all characters. This is NOT equal to "*" becuase it will not match the empty string.

    The following pattern will match the empty string too:

    .*?
    

    so...

    stringMatchWithWildcard ("hello", "hel*lo"); // will give true
    

提交回复
热议问题