开发者

Regular expression on a URL

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/w开发者_C百科ebpic/101

Here is what i have so far.

(.*)(jpg|gif|png|bmp|jpeg|webpic/(\d+))$


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 |
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜