所以,我有一个字符串,我想删除它的电子邮件地址,如果有的话.
例如:
This is some text and it continues like this
until sometimes an email
adress shows up asd@asd.comalso some more text here and here.
结果我想要这个.
This is some text and it continues like this
until sometimes an email
adress shows up [email_removed]also some more text here and here.
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 }
这看起来相当复杂,为什么不使用
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
根据您的需要,随意将模式设置为简单或complicated,但RegExReplace应该这样做.