2012-11-29 3 views
0

에 대한 한 줄에 문자를 대체 할,하지만 난에 수출 이메일 목록에서 일부 문자를 대체 할 수있는 해결책을 찾기 위해 노력하고있어 내 새로운 preg_replace이다()를 사용하여 DB :정규식 내가 정규식 잘 모르겠어요 이메일

을 당신이 정말로 그것을 필요하면
$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: 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
+0

공간 \ S +로 사용하기에 더 나은 될 것입니다. '자정에 만나서'@ 자정 '또는'줄 오류 : 10 ''오류 @ 줄 : 10 '이 되길 원하는지 확실하지 않습니다. –

+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*/

+0

감사합니다. 잘 작동합니다! – user1844923