Reputation: 4247
I want to validate image urls, few with query string and few without it. https://images.company.com/img/800X450/vehicle/201610/858823_589_1475572549658.gif?bg=000000&wmi=n
http://images.company.com/img/800X450/vehicle/201610/858823_599_1475572549658.png
So basic thing is to validate any image with jpg|png|gif|jpeg extension, with or without query string parameter.
I tried using Matches(@".(?i)(jpg|png|gif|jpeg)") regex.
But problem is it is validating images like: http://images.company.com/img/800X450/vehicle/201610/858823_599_1475572549658.pngg OR http://images.company.com/img/800X450/vehicle/201610/858823_599_1475572549658.giff
How can i validate if url has exact extension jpg or png or gif or jpeg and optionally some query string parameter after that?
Upvotes: 1
Views: 1864
Reputation: 4416
Assert that the listed file extension must be followed by a query string or end of string:
(jpg|jpeg|gif|png)((\?+*)?$|$)
Upvotes: 0