在指定字符后使用 RegEx 匹配序列 [英] Match Sequence using RegEx After a Specified Character
问题描述
初始字符串是[image:salmon-v5-09-14-2011.jpg]
我想捕获文本salmon-v5-09-14-2011.jpg"并使用 GSkinner 的 RegEx 工具
I would like to capture the text "salmon-v5-09-14-2011.jpg" and used GSkinner's RegEx Tool
最接近我想要的输出的是使用这个 RegEx:
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!
推荐答案
使用回顾:
(?<=:)[\w+.-]+
后视(编码为 (?<=someregex)
)是零宽度匹配,因此它断言但不捕获匹配.
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 ]
这篇关于在指定字符后使用 RegEx 匹配序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!