开发者

how to implement dos match pattern by php

开发者 https://www.devze.com 2023-03-28 05:44 出处:网络
* represent anything ? represent a character like dos filename *.test.com will match aaa.test.com but not match test.com
* represent anything
? represent a character

like dos filename

*.test.com will match aaa.test.com but not match test.com

a dos like regexp *.test.com is similar with regexp /.*\.test\.com/ in php

is there a builtin function to test dos-like re开发者_开发问答gexp in php?


As far as I can see in your case glob() and/or fnmatch() will do it.

$pattern = '*.test.com';
var_dump(fnmatch($pattern, 'aaa.test.com'));
var_dump(fnmatch($pattern, 'test.com'));

Note, that this are not regular expressions, because this is just a much more simple pattern matching. I don't see a reason, why you should use regex here, thus at least fnmatch() should do it more efficient.

0

精彩评论

暂无评论...
验证码 换一张
取 消