gpt4 book ai didi

regex - 如何从字符串中删除电子邮件地址?

转载 作者:行者123 更新时间:2023-12-04 20:27:47 25 4
gpt4 key购买 nike

所以,我有一个字符串,如果有,我想从中删除电子邮件地址。

例如:

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 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应该这样做。

关于regex - 如何从字符串中删除电子邮件地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54782783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com