提取两个字符之间的文本:Excel 与 Google Sheets

用 MID 加 FIND 取出两个标记之间的文本。对 Price is $12.50 today,在美元符号之后、下一个空格之前得到 12.50。对 SKU-[103]-west,在方括号之间得到 103。对 start(hello)end,在圆括号之间得到 hello。第二个 FIND 要指定起始位置,以免先碰到前面的空格。

本文目录

快速解答

用 MID 加 FIND 取出两个标记之间的文本。对 Price is $12.50 today,在美元符号之后、下一个空格之前得到 12.50。对 SKU-[103]-west,在方括号之间得到 103。对 start(hello)end,在圆括号之间得到 hello。第二个 FIND 要指定起始位置,以免先碰到前面的空格。

=MID(A2,FIND("$",A2)+1,FIND(" ",A2,FIND("$",A2))-FIND("$",A2)-1)

检查要点

没有标记时 FIND 为 #VALUE!,套上 IFERROR 后 no markers here 返回 none。TEXTBEFORE 与 TEXTAFTER 在本文件中为 #NAME?,它们是 Excel 365 的函数。REGEXEXTRACT 用 [0-9]+.[0-9]+ 也能得到 12.50,用 [0-9]+ 从 SKU 行得到 103;但对 start(hello)end 用 [a-z]+ 得到的是 start,不是 hello。

边界与兼容性

若只需按分隔符拆成多列,请看 SPLIT 一文。MID 与 FIND 在 Excel 中同样可用,据微软文档所述;本次未在桌面 Excel 中复测。

完整英文示例、公式与作者备注

Which versions this applies to

The results below were measured in Google Sheets on November 12, 2026. MID and FIND are in Excel as well, per Microsoft. TEXTBEFORE and TEXTAFTER are documented for Excel 365; in this Sheets file they returned #NAME?, same as in #NAME? Error. REGEXEXTRACT is the Sheets function I also ran; Microsoft documents a REGEXEXTRACT for Excel 365, which I did not re-test in desktop Excel today.

MID and FIND between two markers

=MID(A2,FIND("$",A2)+1,FIND(" ",A2,FIND("$",A2))-FIND("$",A2)-1)

On Price is $12.50 today that returned 12.50. The start is one character after the $. The length is the distance from that $ to the next space, minus one, so the space itself is not included. The third argument of the second FIND is a start position: I passed the position of $ so the space I hit is the one after the price, not the space in Price is.

Between brackets, on SKU-[103]-west:

=MID(A3,FIND("[",A3)+1,FIND("]",A3)-FIND("[",A3)-1)

That returned 103. Parentheses worked the same way: start(hello)end returned hello.

If the markers are missing, FIND returns #VALUE! (see FIND vs SEARCH). I wrapped that case with IFERROR(...,"none"), and no markers here returned none.

REGEXEXTRACT, and why I still start with MID

A simple pattern for the price also worked: REGEXEXTRACT(A2,"[0-9]+\.[0-9]+") returned 12.50. REGEXEXTRACT(A3,"[0-9]+") returned 103 from the brackets line.

A loose letter pattern does not mean “between the parentheses.” REGEXEXTRACT("start(hello)end","[a-z]+") returned start, the first run of letters, not hello. If you want the text between two specific characters, write that into the pattern, or use MID/FIND, which already did it.

I had an earlier pattern for a capturing group around the dollar amount that returned #N/A or #REF! after I over-escaped it through the API, so I am not quoting that broken pattern. The two simple patterns above, and the MID formulas, are the ones I actually got clean results from.

Excel and Google Sheets differences

In current Excel, Microsoft documents TEXTBEFORE and TEXTAFTER, which would make this extraction shorter. They are not available in this Google Sheets file (#NAME?). MID and FIND are the overlap I ran and that you can use in both products. SPLIT is a different job — breaking every delimiter into columns — and is in Split Text by Delimiter.

Common mistakes

  • Using the first space in the cell as the end marker when a space also appears before the start marker. Pass a start position to FIND so it looks after the $.
  • Pasting TEXTBEFORE into Google Sheets. It returned #NAME? in this file.
  • Using REGEXEXTRACT with [a-z]+ and expecting the text inside parentheses. It returned start from start(hello)end.
  • Leaving FIND unwrapped on a cell with no markers. That is #VALUE!; IFERROR returned none here.

FAQ

How do I extract text between two characters in Google Sheets?

MID plus two FIND calls is the formula I ran. Between $ and the next space it returned 12.50; between [ and ] it returned 103.

Does TEXTBEFORE work in Google Sheets?

Not in this file. TEXTBEFORE(TEXTAFTER(A2,"$")," ") returned #NAME?.

Why did REGEXEXTRACT return start instead of hello?

The pattern [a-z]+ takes the first run of letters. In start(hello)end, that is start. Use MID/FIND around the parentheses, or a pattern that names those parentheses, if you want hello.

What if one of the characters is missing?

FIND returns #VALUE!. IFERROR(...,"none") returned none on a cell with no brackets.

Will MID and FIND work in Excel?

Yes, according to Microsoft. I did not re-run these exact strings in desktop Excel today. For Excel 365, TEXTBEFORE/TEXTAFTER is the newer path I did not test there.

Live-test findings

Google Sheets, November 12, 2026. MID/FIND on Price is $12.50 today returned 12.50; on SKU-[103]-west returned 103; on start(hello)end returned hello. IFERROR of the bracket formula on no markers here returned none. REGEXEXTRACT with [0-9]+\.[0-9]+ returned 12.50; with [0-9]+ on the SKU line returned 103; with [a-z]+ on start(hello)end returned start. TEXTBEFORE/TEXTAFTER returned #NAME?.

Sources

Oscar

专注电子表格公式与排错;具体测试环境和待验证事项见各篇文章。

Tested in Google Sheets, November 12, 2026. Excel version notes follow Microsoft documentation and were not re-tested in a desktop Excel workbook on this date..

本主题下一篇:数据清理与录入 TEXTJOIN 与 CONCAT:Excel 和 Google Sheets 该用哪一个