【发布时间】:2021-03-16 08:17:05
【问题描述】:
考虑一个字符串:
<! Women's boxing is yet to be recognized as an Olympic support,----. If that happens the dream of most of the tough girls may come true. !> <! dream of most of the tough girls may come true. !> <! Women's boxing is yet to be recognized as an Olympic support. !>
在上面的字符串中,我使用了 作为指定段落边界的分隔符,从字符串中可以明显看出我在分隔符中有 3+1 组封闭语句。
我用来捕获组的正则表达式是
<!([^<!>].+)!>
它匹配的组是:
Group 1: <! Women's boxing is yet to be recognized as an Olympic support,----. If that happens the dream of most of the tough girls may come true. !> <! dream of most of the tough girls may come true. !> <! Women's boxing is yet to be recognized as an Olympic support. !>
Group 2: Women's boxing is yet to be recognized as an Olympic support,----. If that happens the dream of most of the tough girls may come true. !> <! dream of most of the tough girls may come true. !> <! Women's boxing is yet to be recognized as an Olympic support.
我认为匹配包含三个内部组,但它匹配它只包含外部组作为输出。 这是我的预期
//other groups
Women's boxing is yet to be recognized as an Olympic support,----. If that happens the dream of most of the tough girls may come true.
dream of most of the tough girls may come true.
Women's boxing is yet to be recognized as an Olympic support.
【问题讨论】:
-
我觉得你可以用
<!\s*(.*?)!\s*>regex101.com/r/z4qaj2/1 -
@Thefourthbird 我想?成功了。
标签: regex regex-group regex-greedy