正则表达式 - 不符合预期

问题描述 投票:0回答:0

无法得到我想要的正确匹配

我有一个类似于

的模式
<include randomText
    <include randomText
        <arg  name = nameOfInterest
    </include>
    <include randomText
        <arg  name = notInterestedInThis
    </include>
    <include randomText
        <arg  name = nameOfInterest
    </include>
</include>

我正在尝试以下并希望有两场比赛,每个比赛都包含感兴趣的名称

[startIdxs,endIdxs] = regexp(string,'<(\w+).*>.*nameOfInterest.*</\1>')

相反,它所做的是从包含 Name of Interest 的第一部分的开头一直匹配到文件末尾的最后一个 include

这是一场有效的比赛,但不是我希望的比赛。

有没有办法只匹配包含感兴趣的参数名称的开始/结束包含,而不跳到最后一个包含?

希望这是有道理的

regex matlab pattern-matching
© www.soinside.com 2019 - 2024. All rights reserved.