You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Excel字符串提取需求:提取指定片段与分隔符后文本并移除末尾字符

问题需求与修正方案

需求说明

需要从包含多个-分隔符的文本字段中提取两段内容:

  • 提取字符串的第3至第6位字符
  • 提取最后一个-之后的文本,并移除该部分的最后一个字符

示例

示例输入:
1-7483742 (first part of the string-second part of the string)
1-1234742 (first part of the string-some other part)
1-5678742 (first part of the string-and more text)

期望输出:
7483 second part of the string
1234 some other part
5678 and more text

用户尝试的公式

=IFERROR(RIGHT(LEFT([@[sourcecolumn]],6),4)&" "&MID([@[sourcecolumn]], FIND("-", [@[sourcecolumn]], FIND("-", [@[sourcecolumn]])+1)+1,256),RIGHT(LEFT([@[sourcecolumn]],6),4))

修正后的公式

=IFERROR(RIGHT(LEFT([@[sourcecolumn]],6),4)&" "&LEFT(MID([@[sourcecolumn]], FIND("-", [@[sourcecolumn]], FIND("-", [@[sourcecolumn]])+1)+1,256), LEN(MID([@[sourcecolumn]], FIND("-", [@[sourcecolumn]], FIND("-", [@[sourcecolumn]])+1)+1,256))-1),RIGHT(LEFT([@[sourcecolumn]],6),4))

修正说明

原公式已经正确提取了最后一个-后的文本,但未移除末尾字符。只需将提取该部分文本的MID函数嵌套进LEFT函数,通过LEN(提取的文本)-1截取到倒数第二个字符,即可实现移除最后一个字符的要求。

如果想简化公式(避免重复书写MID部分),可使用LET函数(适用于Excel 365及后续版本):

=LET(
    part1, RIGHT(LEFT([@[sourcecolumn]],6),4),
    part2_raw, MID([@[sourcecolumn]], FIND("-", [@[sourcecolumn]], FIND("-", [@[sourcecolumn]])+1)+1,256),
    part2, LEFT(part2_raw, LEN(part2_raw)-1),
    IFERROR(part1&" "&part2, part1)
)

内容的提问来源于stack exchange,提问作者digerati

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 16:08:13