[英]Regex to match specific file names
I am trying to parse some HTML of a directory listing page using c#. That page has many file urls like "0220109_120548.046.jpg" but has also others like "0220109_120548.046-445x265.jpg".我正在尝试使用 c# 解析目录列表页面的一些 HTML。该页面有许多文件 url,如“0220109_120548.046.jpg”,但也有其他的,如“0220109_120548.046-445x265.jpg”。 They are the same picture but one has its dimensions in the name.
它们是同一张照片,但名称中有其尺寸。
I need a regex to match only the urls of those files without the dimensions.我需要一个正则表达式来匹配那些没有尺寸的文件的网址。
I tried this one: href="^"*.(gif|jpg|png)"我试过这个:href="^"*.(gif|jpg|png)"
but its not working.但它不工作。
the regex101 url: https://regex101.com/r/APS9NY/1 regex101 url: https://regex101.com/r/APS9NY/1
Here is one way to do so:这是一种方法:
href=\"[^\"]*?(?<!\d{2,4}x\d{2,4})\.(gif|jpg|png)\"
See here for the online demo.请在此处查看在线演示。
href=\"
: Matches href="
href=\"
:匹配href="
[^\"]*?
: Any character that isn't "
, between zero and unlimited times, as few as possible. [^\"]*?
:任何不是"
的字符,在零次和无限次之间,尽可能少。(?<!)
: Negative lookbehind. (?<!)
:负向后看。
\d{2,4}
: Matches between 2 and 4 digits. \d{2,4}
:匹配 2 到 4 位数字。x
: Matches x
. x
:匹配x
。\.
: Matches .
.
. (gif|jpg|png)
: Matches either gif
, jpg
or png
. (gif|jpg|png)
:匹配gif
、 jpg
或png
。\"
: Matches "
. \"
:匹配"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.