2016-08-18 2 views
-1

문자열에서 전자 메일을 추출하고 싶습니다.
문자열이 abc defg [email protected]이고 문자열을 [email protected] (으)로하고 싶습니다.문자열에서 전자 메일을 추출하는 방법

PL/SQL에서 어떻게 할 수 있습니까?

+0

다음을 확인하십시오. http://www.orafaq.com/forum/t/189919/ – Petaflop

+0

이메일이 항상 마지막일까요? – sagi

+0

문자열을 검색하여 @를 Len의 공백 문자로 전달한 다음 전체 스팅으로 해당 int의 ngram 토큰을 가져올 수 있습니다. 그것의 고통 그러나 doable 및 aestways 일 것이다. 데이터 샘플이 있습니까? – Merenix

답변

1

뭔가 많은 상황에서 작동하지만 완벽과는 거리가 먼 것입니다. 이것이 실패 할 수있는 두 가지 방법을 보여주는 문자열 하나를 추가했습니다. 가능한 모든 상황을 포착하는 쿼리를 작성하는 것은 쉽지 않을 것입니다. "매치 패턴"을 더 상세하게 파악하는 데 걸리는 시간은 입력 데이터의 전자 메일이 얼마나 비정상인지에 따라 다릅니다.

정규 표현식에서 점 (.)은 백 슬래시로 이스케이프해야하며 일치하는 목록 (대괄호 안의 문자 목록)에서 하이픈은 목록의 첫 번째 문자 또는 마지막 문자 여야합니다 , 다른 곳에서는 메타 문자입니다.

출력시 마지막 행을 확인하십시오. 입력 문자열은 비어 있으므로 출력도 null입니다.

with 
    input_strings (str) as (
     select 'sdss [email protected] sdsda sdsds '   from dual union all 
     select '[email protected] may not work'    from dual union all 
     select '[email protected], [email protected],[email protected]' from dual union all 
     select ''           from dual union all 
     select 'this string contains no email addresses'  from dual union all 
     select '-this:[email protected]_domain'   from dual union all 
     select '[email protected] [email protected]@mike.com'  from dual 
    ) 
select str as original_string, 
     level as idx, 
     regexp_substr(str, '[[:alnum:]_-][email protected][[:alnum:]_-]+\.[[:alnum:]_-]+', 1, level) 
                     as email_address 
from input_strings 
connect by regexp_substr(str, '[[:alnum:]_-][email protected][[:alnum:]_-]+\.[[:alnum:]_-]+', 1, level) 
                       is not null 
    and prior str = str 
    and prior sys_guid() is not null 
; 

ORIGINAL_STRING         IDX EMAIL_ADDRESS 
------------------------------------------- ---------- -------------------------------- 
-this:[email protected]_domain     1 [email protected]_domain 
[email protected] [email protected]@mike.com    1 [email protected] 
[email protected] [email protected]@mike.com    2 [email protected] 
[email protected] may not work      1 [email protected] 
sdss [email protected] sdsda sdsds      1 [email protected] 
[email protected], [email protected],[email protected]   1 [email protected] 
[email protected], [email protected],[email protected]   2 [email protected] 
[email protected], [email protected],[email protected]   3 [email protected] 
this string contains no email addresses    1 
                1 

10 rows selected. 
관련 문제