javascript - How to determine whether a path is containing a format at the end? -


i have urls these:

http://example.com/class/method/arg1 http://example.com/class/method/image.jpg http://example.com/class/method/arg1.png http://example.com/class/method/arg1/arg2/ http://example.com/class/method/arg1.gif/ 

i want output in order:

false true true false true 

so, see in examples above, i'm trying detect path image or not .. how can that?


this regex checks 4 last characters .jpg:

^.*([^.]...|.[^j]..|..[^p].|...[^g])$ 

i can write multiple regex cases (.png, .gif, ...), want know, there better solution?

if you're looking strings end in .jpg, .gif or .png need

\.(?:jpg|gif|png)$ 

Comments