How to use RegexIterator in PHP

后端 未结 3 909
长情又很酷
长情又很酷 2020-11-27 15:27

I have yet to find a good example of how to use the php RegexIterator to recursively traverse a directory.

The end result would be I want to specify a directory an

3条回答
  •  北海茫月
    2020-11-27 16:14

    The docs are indeed not much helpful. There's a problem using a regex for 'does not match' here, but we'll illustrate a working example first:

    
    

    The problem is the doesn't match .Trash[0-9]{3} part: The only way I know how to negative match the directory, is match the end of the string $, and then then assert with a lookbehind (? 'if it is not preceded by '/foo'.

    However, as .Trash[0-9]{1,3} is not fixed length, we cannot use it as a lookbehind assertion. Unfortunately, there is no 'invert match' for a RegexIterator. But perhaps there are more regex-savvy people then I knowing how to match 'any string not ending with .Trash[0-9]+


    edit: got it '%([^0-9]|^)(? as a regex would do the trick.

提交回复
热议问题