1

我想要一个正则表达式来匹配来自字符串(一个 url)的图像格式,但避免使用具体的域或目录。例如:

“myImages/small/myImage.png”

“我的图像/xxxx/myImage.png”

“myImages/大/myImage.png”

我想要一个正则表达式来匹配任何但不是“大”的......

提前谢谢了!

4

1 回答 1

3

You want a negative lookahead assertion:

myImages\/(?!large\/).+\.(?:png|jpg|gif|jpeg|svg)$

The above will match any path that ends with one of those file extensions, but that does not have the text "large/" following "myImages/".

It's not very clear what your needs are, what output you want and what you can and cannot anchor against. If you edit your question to be more clear, you can get more-targeted information.

于 2012-05-24T15:20:49.213 回答