几乎正则表达式与 glob

Nearly regex with glob

PHP的glob好像支持limited-range of regex-like syntax.

我想赶上hello<somethingherebutonlyifitbeginsby#>.txt,即:

我试过了

glob('hello#?*.txt', GLOB_BRACE);

但它不起作用。我们如何纠正它?

glob's regex also supports character classes and negative character classes, using the syntax [] and [^]. It will match any one character inside [] or match any one character that is not in [^].

hello.txt: ok
hello#you.txt: ok
hellome.txt: not ok
//[] include chars. and #
var_dump(glob('hello[.#]*txt', GLOB_BRACE));

array(2) {
[0]=>
 string(13) "hello#you.txt"
[1]=>
 string(9) "hello.txt"
}


>ls hello* 
hellome.txt  hello.txt  hello#you.txt

你可以这样写:

glob('hello{#*,}.txt', GLOB_BRACE);

其中 {aa,bb} 是一个替代(GLOB_BRACE 和支持它的操作系统可用的功能)。