$A -replace 'Send email to: ' -replace '\.$'
[email protected]
有一些字符串(它的末尾总是应该是。)
$A = 'Send email to: [email protected].'
据我所知,还有一些代码应删除除电子邮件以外的所有内容
(([regex]'Send email to:(.*?)\.').Match($A).Value -replace "Send email to: |\.") -replace ";$"
问题是代码坏了,使它产生
mail@domain
代替
[email protected]
如何解决,“; $”是什么意思?
$1
中>\bSend email to: ([^@\s]+@[^\s@]+\.[^\s@.]+)\.
[\bSend email to:
字面匹配的单词边界
(
捕获组1[^@\s]+
匹配1个以上字符,@或空格字符除外] >>@[^\s@]+
匹配@
,后跟上一个模式\.[^\s@.]+
匹配.
,后跟上一个模式)\.
关闭组并匹配点]$A = 'Send email to: [email protected].'
$A -replace 'Send email to: ([^@\s]+@[^\s@]+\.[^\s@.]+)\.','$1'
输出
[email protected]
如何删除不需要的内容。$
表示行的结尾。.
表示任何字符,因此需要使用\
进行转义。 -replace的第二个参数都没有暗示用$ null替换它,或删除它。$A -replace 'Send email to: ' -replace '\.$' [email protected]