Page 1 of 1

PHP regular expression issues for excluding or including files

Posted: 13 Nov 2021, 22:30
by amwpsaa
PHP regular expression issues for excluding or including files,

I want to hide the .php.js.css extension, which can be written like this:
Code
'files_exclude' =>'/\.(php|js|css)$/i',
I also want to hide the hidden.jpg file. It can be written like this:
Code
'files_exclude' =>'/hidden.jpg/',
I don’t know how to combine wording, please ask  Karl, thank you

Re: PHP regular expression issues for excluding or including files

Posted: 13 Nov 2021, 23:52
by mjau-mjau
I'm not an expert with regex, but I think that can be achived like this:
Code
'files_exclude' =>'/\.(php|js|css)$|^hidden.jpg$/i',
The above will hide only exact file name "hidden.jpg", because I included ^starts and ends$. I used this tool to test:
https://www.phpliveregex.com/

PS! You can also create filenames that start with _files* (for example _fileshidden.jpg), which will automatically be hidden.

Re: PHP regular expression issues for excluding or including files

Posted: 14 Nov 2021, 01:13
by amwpsaa
mjau-mjau wrote: I'm not an expert with regex, but I think that can be achived like this:
Code
'files_exclude' =>'/\.(php|js|css)$|^hidden.jpg$/i',
The above will hide only exact file name "hidden.jpg", because I included ^starts and ends$. I used this tool to test:
https://www.phpliveregex.com/
No, there's a mistake!

Error
Invalid files_exclude regex /\.(php|js|css)$|^hidden.jpg$/i/

PS! You can also create filenames that start with _files* (for example _fileshidden.jpg), which will automatically be hidden.
I want to customize my name.

Re: PHP regular expression issues for excluding or including files

Posted: 14 Nov 2021, 02:57
by mjau-mjau
amwpsaa wrote:Error
Invalid files_exclude regex /\.(php|js|css)$|^hidden.jpg$/i/
Not sure where you get /i/ from with ending/. It should be /i not /i/.

I have tried and tested it successfully from here. You can try to escape the \. dot:
Code
'files_exclude' =>'/\.(php|js|css)$|^hidden\.jpg$/i',