Reputation: 25
I need to be able to catch when the URL contains a image of multiple file types or follow this syntax.
http://localhost:8080/fdlic-web/webpic/101
Here is what i have so far.
(.*)(jpg|gif|png|bmp|jpeg|webpic/(\d+))$
Upvotes: 1
Views: 206
Reputation: 338406
Good so far, just use less grouping and kick out the .*
, you don't need it.
(?:webpic/\d+|gif|png|bmp|jpe?g)$
Actually, it's less ambiguous to delimit your directories/file types to prevent partial matches that yield false positives:
(?:/(?:webpic/\d+)|\.(?:gif|png|bmp|jpe?g))$
^ ^
| all path components here |
all file extensions here |
Upvotes: 2