use*_*570 19 regex excel replace
我有一个包含1列和多行的excel文件.
行包含各种文本,这是一个示例:
texts are home
texts are whatever
dafds
dgretwer
werweerqwr
texts are 21412
texts are 346345
texts are rwefdg
terfesfasd
rwerw
Run Code Online (Sandbox Code Playgroud)
我想替换"文本是*",其中*是"文本是"之后的任何内容,具有特定的单词,例如"文本被替换".我怎么能在Excel中这样做?
Cra*_*rag 26
使用Google表格而不是Excel - 此功能是内置的,因此您可以直接使用查找和替换对话框中的正则表达式.
回答你的问题:
cri*_*fan 11
现在是2021年了,你可以使用Excel的替换
texts are *
texts are replaced
Ham*_*han 11
显然,Excel 不使用正则表达式,但有一个解决方法。您可以使用 *, ?或 ~ 在您的搜索模式中。
寻找
? (question mark) = Any single character. For example, sm?th finds "smith" and "smyth"
* (asterisk) = Any number of characters For example, *east finds "Northeast" and "Southeast"
~ (tilde) followed by ?, *, or ~ = A question mark, asterisk, or tilde. For example, fy06~? finds "fy06?"
Run Code Online (Sandbox Code Playgroud)
您可以使用这些组合来获得接近正则表达式的相似模式。
如果您希望公式执行此操作,请执行以下操作:
=IF(ISNUMBER(SEARCH("*texts are *",A1)),LEFT(A1,FIND("texts are ",A1) + 9) & "WORD",A1)
Run Code Online (Sandbox Code Playgroud)
这样就可以了。将`“ WORD”更改为所需的单词。
作为正则表达式的替代方案,运行:
Sub Replacer()
Dim N As Long, i As Long
N = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To N
If Left(Cells(i, "A").Value, 9) = "texts are" Then
Cells(i, "A").Value = "texts are replaced"
End If
Next i
End Sub
Run Code Online (Sandbox Code Playgroud)
将产生: