繁体   English   中英

Excel 公式查找前缀后两个单词

[英]Excel formula to find two words after the prefix

我正在将 Jira 问题导出到 Excel 以从描述中提取数据。

格式示例如下:“作者:Bob Bryant 这是一个测试 JIRA”

这样整个字符串在 Excel 中占据一个单元格

我需要做一个=IF(ISNUMBER(SEARCH("*Author*",Description)),"Author:","")

但我需要它代替“作者:”之后的 2 个词(用户全名),在这种情况下,我需要它来代替“鲍勃·布莱恩特”

不幸的是,Excel 不能使用正则表达式(这会容易得多)。 您可以使用SUBSTITUTE function 通过临时文本替换来解决它。

和:

  • Prefix - 带有前缀的单元格,例如“作者:”
  • Description - 带有原始/源文本的单元格

这是您需要的公式是:

=IF(ISERR(SEARCH(Prefix;Description));"(no "&Prefix&" found)";IFERROR(TRIM(MID(Description;LEN(Prefix)+1;SEARCH("$$$";SUBSTITUTE(Description&" ";" ";"$$$";3))-LEN(Prefix)));"(too short)"))

让我们更深入地解释一下:

=IF(                                     
    ISERR(SEARCH(Prefix;Description));    -- consider only cells with the right prefix (Author:)
    "(no "&Prefix&" found)";              -- Prefix not found: return message
    IFERROR(                              -- Prefix found: proceed
        TRIM(                             -- remove any leading/trailing spaces
            MID(                          -- return the text between prefix and 3rd space
                Description;
                LEN(Prefix)+1;            -- start after the prefix
                SEARCH(                   -- end before the substituted text ($$$)
                    "$$$";
                    SUBSTITUTE(           -- substitute 3rd space (most important!)
                        Description&" ";  -- add extra space (in case there's no other text after the name)
                        " ";
                        "$$$";
                        3))-LEN(Prefix)));"(too short)"))

请注意,您可能需要更换; 在您的公式中使用, (取决于您的系统区域设置/区域设置)。

暂无
暂无

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

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