Search code examples
phpregexglob

Nearly regex with glob


PHP's glob seems to support a limited-range of regex-like syntax.

I would like to catch hello<somethingherebutonlyifitbeginsby#>.txt, i.e.:

  • hello.txt: ok
  • hello#you.txt: ok
  • hellome.txt: not ok

I tried

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

but it doesn't work. How can we correct it?


Solution

  • You can write it like that:

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

    where {aa,bb} is an alternation (feature available with the GLOB_BRACE and with OSes that support it).