Forum Moderators: phranque

Message Too Old, No Replies

Basic regex question

matching images in root directory

         

simplys

12:56 am on Apr 18, 2006 (gmt 0)

10+ Year Member



I'd like to match all the images in the root directory and I wanted to ask you if this is the most efficient and correct way of doing it.

Using it with apache mod_rewrite

^([^/\.])\.(jpg¦jpeg¦gif¦png¦bmp)$

thank you,
Catalin

jdMorgan

1:48 am on Apr 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That should work if you add a "+" in there, but there's no need to escape the "." in the [group] and you can 'compress' the jpeg-jpg filetype patterns:

^([^/.]+)\.(jpe?g¦gif¦png¦bmp)$


Also, if you intend to back-reference the path, you can nest the parentheses:

^([^/.]+\.(jpe?g¦gif¦png¦bmp))$

That will allow you to back-reference the full path using $1 only.

Jim