在正则表达式中,是否有任何方法不返回完全匹配,而仅返回组匹配?
我需要清理输出。
例如此文本:
std::endl
这种模式:aaa foo bar1 baz sss
ddd foo bar2 baz fff
您可以在此处查看结果:https://regex101.com/r/7wLDNK/2 输出:
foo (.*?) baz
您也可以在这里看到js代码:https://jsfiddle.net/NabiKAZ/02sycL7a/3 输出:
Match 1
Full match 4-16 `foo bar1 baz`
Group 1. n/a `bar1`
Match 2
Full match 25-37 `foo bar2 baz`
Group 1. n/a `bar2`
我不需要regex101站点中的Found match, group 0: foo bar1 baz
Found match, group 1: bar1
Found match, group 0: foo bar2 baz
Found match, group 1: bar2
,foo bar1 baz
完全匹配,而我只想查看组匹配(foo bar2 baz
,bar1
,...)。