所以,我有一个字符串,我想删除它的电子邮件地址,如果有的话.
例如:
这是一些文字,它会继续这样,
直到有时电子邮件地址显示为asd@asd.com还有一些文字在这里和这里.
结果我想要这个.
这是一些文字,它会继续这样,
直到有时电子邮件地址出现[email_removed]还有一些文字在这里和这里.
cleanFromEmail(string)
{
newWordString =
space := a_space
Needle = @
wordArray := StrSplit(string, [" ", "`n"])
Loop % wordArray.MaxIndex()
{
thisWord := wordArray[A_Index]
IfInString, thisWord, %Needle%
{
newWordString = %newWordString%%space%(email_removed)%space%
}
else
{
newWordString = %newWordString%%space%%thisWord%%space%
;msgbox asd
}
}
return newWordString
}
Run Code Online (Sandbox Code Playgroud)
这个问题是我最终失去了所有换行符并且只获得了空格.如何在重新删除电子邮件地址之前重新构建字符串?
看起来相当复杂,为什么不RegExReplace直接使用呢?
string =
(
This is some text and it continues like this
until sometimes an email adress shows up asd@asd.com
also some more text here and here.
)
newWordString := RegExReplace(string, "\S+@\S+(?:\.\S+)+", "[email_removed]")
MsgBox, % newWordString
Run Code Online (Sandbox Code Playgroud)
根据您的需要,您可以随意使图案变得简单或复杂RegExReplace,但应该这样做。