1
votes

I need a Regular Expression to accept the URL ending with all file Types: Like "http://other-images.contenix.com/BrandAssets/55957/care_guide.pdf" or "http://upload.wikimedia.org/wikipedia/commons/9/9a/Avenger_-_Westphalian_horse.jpg" .

I have tried this: "^..(gif|jpg|jpeg|png|bmp|GIF|JPEG|JPG|PNG|BMP|Gif|Jpg|Jpeg|Png|Bmp)\s$", but this only allows only image file.

Now my requirement has changed for all File Types.

****EDIT

Can i make something like there should be a "." among the characters after the URL final slash "/"

Any Help Appreciated.

Thanks

2
@AvinashRaj: Not a very good approachMufaddal
there are so many filetypes. How would we create a regex for you to allow all the filetypes?Avinash Raj
If you're accepting all types, why do you need a regular expression? Just accept the type, whatever it is.Carl
can i make something like there should be a "." among the characters after the URL final slash "/"Mufaddal
try ^.*\/[^.]*\.\w+\s*$Avinash Raj

2 Answers

1
votes

Thats a tricky question because the types of files can be many .. as many as .. may be 500+ you can check out the list here

Better off list all the file formats that you are to allow, and then just keep on adding them with a | (pipe). As you have done for image extensions.

To make sure that your url will contain a dot use :

^.*?\.\w+$

demo here : http://regex101.com/r/sL8vF1/1

1
votes

To match all the URL's which contain a dot after the final / symbol is as below.

^.*\/[^.]*\.\w+\s*$