简体   繁体   English

Excel 为多个可能的字符串删除字符串前的文本

[英]Excel Remove text before string for multiple possible strings

With Excel, I need to find and remove some text from all cells in a column.对于 Excel,我需要从列中的所有单元格中查找并删除一些文本。 Using the example below I need get all instances of DEV* and BA* into another column.使用下面的示例,我需要将 DEV* 和 BA* 的所有实例放入另一列。

Example data in a column:列中的示例数据:
Data数据
Dan Smith DEV001丹·史密斯 DEV001
Bob Jones BA005鲍勃·琼斯 BA005
Bob Jones2 BA 005鲍勃·琼斯2 BA 005

Needed Result需要的结果
DEV001开发001
BA005 BA005
BA 005巴005

This example works partially but not with multiple possible matches.此示例部分有效,但不适用于多个可能的匹配项。

=TRIM(RIGHT(A2, LEN(A2) - SEARCH("DEV", A2)))

How can this be done with multiple possible matches?如何通过多个可能的匹配项来做到这一点?

Try using this尝试使用这个

• Formula used in cell B1 • 单元格B1中使用的公式

=REPLACE(A1,1,MAX(IFERROR(FIND({"DEV","BA"},A1),""))-1,"")

配方_溶液

Here is something to consider for those using ms365 with access to TEXTBEFORE() :对于那些使用 ms365 并可以访问TEXTBEFORE()的用户,需要考虑以下事项:

在此处输入图像描述

Formula in B1 : B1中的公式:

=SUBSTITUTE(A1,TEXTBEFORE(A1,{"DEV","BA"}),"",1)
  • TEXTBEFORE() - will look (case sensitive) for either 'DEV' or 'BA' and will return the substring before the 1st occurence of any of these two; TEXTBEFORE() - 将查找(区分大小写)“DEV”或“BA”,并将在这两个中的任何一个第一次出现之前返回 substring;
  • SUBSTITUTE() - will replace (also case sensitive) this returned substring with nothing. SUBSTITUTE() - 将替换(也区分大小写)返回的 substring 为空。 And to make sure we won't substitute unwanted parts after the lookup value we only replace the 1st occurence.并且为了确保我们不会在查找值之后替换不需要的部分,我们只替换第一次出现的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM