正则表达式 – 如何从字符串中删除电子邮件地址?
发布时间:2020-12-14 02:29:05 所属栏目:百科 来源:网络整理
导读:所以,我有一个字符串,我想删除它的电子邮件地址,如果有的话. 例如: 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. 结果我想要这个. This is some text and it c
所以,我有一个字符串,我想删除它的电子邮件地址,如果有的话.
例如:
结果我想要这个.
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应该这样做. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |