这是我的正则表达式:(<ImageContainer)([\s\S]+)([\s\S]+)(<\/ImageContainer>)
以下是我抓住的一些文字:
<ImageContainer>some stuff here...<\ImageContainer>more stuff here..<ImageContainer>and even more stuff</ImageContainer>...
我的正则表达式正在抓取整个文本,我只希望它从<ImageContainer>
抓取到</ImageContainer>
。我错过了什么?
答案 0 :(得分:2)
<ImageContainer>(.*?)<\/ImageContainer>
序列.*?
一次只能吃一个字符,然后尝试让模式的其余部分匹配。将此与常规贪婪.*
进行对比,它会立即竞争到字符串的末尾,然后回溯以尝试让模式的其余部分匹配。