简体   繁体   English

将字符串转换为电子邮件地址

[英]Convert String to e-mail address

I am writing a script that will rename so exported PST files to match the format needed for import to a new system. 我正在编写一个脚本,该脚本将重命名,以便导出的PST文件与导入到新系统所需的格式匹配。

I am trying to use regular expression in VBScript to do this along with Replace. 我正在尝试在VBScript中使用正则表达式以及“替换”来做到这一点。

An example string: 一个示例字符串:

JoeBloggs_Export_001.pst

Required End Result: 所需的最终结果:

Joe.Bloggs@emaildomain.com._001.pst

I have obviously got the replace of Export with @emaildomain.com. 我显然已经用@ emaildomain.com替换了Export working with Replace. 使用替换。

I am struggling to get the insert of . 我正在努力获得的插入。 between the First-name and Last-name, I figured using a regular expression to do this would be the best approach. 在名和姓之间,我认为使用正则表达式可以做到这一点。 I am struggling with getting this to work. 我正在努力使它起作用。 Obviously the length of the first-name varies. 显然,名字的长度是变化的。

I have now tried various regular expressions, so rather than sharing any of these I am hoping getting a fresh set of eyes will help to highlight where I have been going wrong. 我现在已经尝试了各种正则表达式,因此与其共享其中的任何一种,我希望能看到一些新的知识,这有助于突出我出了问题的地方。

Many thanks in advance. 提前谢谢了。

Mark 标记

Assuming you want to break the pascal cased name on caps you can capture lower-case followed by upper-case & insert a "."; 假设您想打破大写的pascal大小写名称,可以先捕获小写字母,再捕获大写字母,并插入“。”;

set re = New RegExp
re.Pattern = "([a-z])([A-Z])"
re.global = true

filename = "JoeBloggs_Export_001.pst"

msgbox replace(re.Replace(fileName, "$1.$2"), "_Export_", "@emaildomain.com._")

>> Joe.Bloggs@emaildomain.com._001.pst

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM