Regexextract在一个单元格中的多个行上

时间:2021-03-20 22:22:23

In Google Sheets, I have this in one cell:

在谷歌表中,我有一个单元格:

Random stuff blah blah 123456789
<Surname, Name><123456><A><100><B><200>
<Surname2, Name2><456789><A><300><B><400>
Some more random stuff

And would like to match the strings within <> brackets. With = REGEXEXTRACT(A4, "<(.*)>") I got thus far:

并希望匹配<>括号内的字符串。与= REGEXEXTRACT(A4, <(.*)>):

Surname, Name><123456><A><100><B><200

which is nice, but it is only the first line. The desired output would be this (maybe including the <> at the beginning/end, it doesn't really matter):

这很好,但这只是第一行。期望输出是这样的(可能包括<>在开始/结束时,其实并不重要):

Surname, Name><123456><A><100><B><200>
<Surname2, Name2><456789><A><300><B><400

or simply:

或者仅仅是:

Surname, Name><123456><A><100><B><200><Surname2, Name2><456789><A><300><B><400

How to get there?

如何到达那里?

1 个解决方案

#1


3  

Please try:

请尝试:

=SUBSTITUTE(regexextract(substitute(A4,char(10)," "),"<(.*)>"),"> <",">"&char(10)&"<")

Starting in the middle, the substitute replaces line breaks (char(10)) with spaces. This enables the regexextract the complete (ie multi-line) string to work on, with the same pattern as already familiar to OP. SUBSTITUTE then reinstates the relevant space (identified as being immediately surrounded by > and <) with a line break.

从中间开始,替换用空格替换换行符(char(10))。这使regexextract能够处理完整的(即多行)字符串,其模式与ope已经熟悉的模式相同。

#1


3  

Please try:

请尝试:

=SUBSTITUTE(regexextract(substitute(A4,char(10)," "),"<(.*)>"),"> <",">"&char(10)&"<")

Starting in the middle, the substitute replaces line breaks (char(10)) with spaces. This enables the regexextract the complete (ie multi-line) string to work on, with the same pattern as already familiar to OP. SUBSTITUTE then reinstates the relevant space (identified as being immediately surrounded by > and <) with a line break.

从中间开始,替换用空格替换换行符(char(10))。这使regexextract能够处理完整的(即多行)字符串,其模式与ope已经熟悉的模式相同。