在指定字符之后使用Regex匹配序列

发布于 2025-02-06 17:07:41 字数 406 浏览 1 评论 0原文

初始字符串是 [图像:Salmon-V5-09-14-2011.jpg]

我想捕获文本“ Salmon-V5-09-14-2011.jpg”,并使用 gskinner的正则福克斯工具

我能获得的最接近我所需的输出的最接近的是使用此言论:

:([\w+.-]+)

问题是,这个序列包括该序列包括colon colon colon 输出

:salmon-v5-09-14-2011.jpg

如果没有结肠, 如何捕获所需的输出。感谢您的帮助!

The initial string is [image:salmon-v5-09-14-2011.jpg]

I would like to capture the text "salmon-v5-09-14-2011.jpg" and used GSkinner's RegEx Tool

The closest I can get to my desired output is using this RegEx:

:([\w+.-]+)

The problem is that this sequence includes the colon and the output becomes

:salmon-v5-09-14-2011.jpg

How can I capture the desired output without the colon. Thanks for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

软糖 2025-02-13 17:07:41

使用外观范围:

(?<=:)[\w+.-]+

look-behind(编码为(?&lt; = somereGex))是一个零宽的匹配,因此它断言,但并未捕获匹配项。

另外,您的正则表达式可能可以简化:

(?<=:)[^\]]+

它只是抓住(但不包括)和a ] 之间的任何内容

Use a look-behind:

(?<=:)[\w+.-]+

A look-behind (coded as (?<=someregex)) is a zero-width match, so it asserts, but does not capture, the match.

Also, your regex may be able to be simplified to this:

(?<=:)[^\]]+

which simply grabs anything between (but not including) a : and a ]

偷得浮生 2025-02-13 17:07:41

如果您一直以这种格式查看字符串,我将使用此模式:

(?<=\[image:)[^\]]+

这是的后面。

If you are always looking at strings in that format, I would use this pattern:

(?<=\[image:)[^\]]+

This looks behind for [image:, then matches until the closing ]

您只有正确的正则是您使用的工具,而是突出显示整个比赛,而不仅仅是您的捕获组。在比赛中徘徊,看看“第1组”实际是什么。

如果您想要更强大的正则义务。

You have the correct regex only the tool you're using is highlighting the entire match and not just your capture group. Hover over the match and see what "group 1" actually is.

If you want a slightly more robust regex you could try :([^\]]+) which will allow for any characters other than ] to appear in the file name portion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文