我不擅长正则表达式,但我正在尝试使用preg_replace()从导出到我的新数据库的电子邮件列表中找到替换某些字符的解决方案:
$patterns1 = '/\[at\]/'; '/\(at\)/'; '/\{at\}/'; '/\ at\ /';
$replacements1 = '@';
$patterns2 = '/\[dot\]/'; '/\(dot\)/'; '/\{dot\}/'; '/\ dot\ /';
$replacements2 = '.';
input:
username [at] subdomain [dot] domain [dot] com
username {at} subdomain {dot} domain {dot} com
username (at) subdomain (dot) domain (dot) com
username at subdomain dot domain dot com
username[at]subdomain[dot]domain[dot]com
username{at}subdomain{dot}domain{dot}com
username(at)subdomain(dot)domain(dot)com
output:
username@subdomain.domain.com
username@subdomain.domain.com
username@subdomain.domain.com
username@subdomain.domain.com
username@subdomain.domain.com
username@subdomain.domain.com
username@subdomain.domain.com
答案 0 :(得分:1)
如果你真的需要它,这对我有用:
$ echo 'me {at)somewhere dot com' | perl -lane 's/(\s*[({\[ ]at[)}\] ]\s*)/@/g; s/(\s*[({\[ ]dot[)}\] ]\s*)/./g;print'
您的模式将为/\s*[({\[ ]at[)}\] ]\s*/
和/\s*[({\[ ]dot[)}\] ]\s*/