这里有几个带有烫发链接的解决方案。文件/屏幕截图。
A) 正则表达式 - re2(表格)
有关文件关联,请参阅here。上面有截图。
B) 中间/搜索公式
=Mid(B4,search($C$3,B4)+len($C$3)+1,len(B4))
地点:
- 第一个“数据”点位于单元格 B4 中(即您提供的句子“KIM - 2021 COMPLETE - OLAP - 03-01-2021...DONE=> APWC....”
- 单元格 C3 中所需的“触发”词(例如“DONE=>”) - 您可以将其更改为您希望的任何内容(仅选取第一次出现,并将其后的所有内容作为 req 返回。
- 返回的文本:C 列(单元格 C4 中的第一个结果)
工作原理
- Mid(target,a,b) 从 target 单元格中的文本返回 b 个字符,从 'ath' 位置的字符开始
- 例如with target = "Hello", a = 2 and b = 3, Mid("Hello",2,3) = "ell"(不带引号)
- 对于您的情况,使用 a = search("DONE=>") 从该点(单词开头)返回文本,因此 a = search("DONE=>")+ len("DONE=>") + 1 应该将结果字符串的第一个字符放置在第一次出现单词“DONE=>”之后立即返回
- len(string) 只返回定义为字符串的变量的长度。例如。 len("Hello") = 5。由于“DONE=>”后面的字符数不可能超过原始文本中的字符总数(即您的“数据”),Excel会自动限制最大可用字符,因此您可以放心,“DONE=>”之后的所有字符都会返回(假设该词在数据中出现)
- Iferror 和 Trim 只是为了确保结果更清晰(例如,缺少“DONE=>”、多余的空格字符等)
截图
Formulation of mid / search example
C) 正则表达式变体
工作表将 re2 用于正则表达式。普通的 RegEx 应该是这样的:
(DONE=>\K)..+
参见here(永久链接可用于转换为 python/java 等)。例如。在 Python 中,这将按如下方式工作:
# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(DONE=>\K)..+"
test_str = "KIM - 2021 COMPLETE - OLAP - 03-01-2021...DONE=> APWC 02-2021, BCMOI 02-2021, QAF 02-2021, PPN 02-2021"
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
D) 相关链接