我想從字符串中提取電子郵件。
我有字符串abc defg [email protected]
,我想要得到字符串[email protected]
。如何從字符串中提取電子郵件
我怎麼能在PL/SQL中做到這一點?
我想從字符串中提取電子郵件。
我有字符串abc defg [email protected]
,我想要得到字符串[email protected]
。如何從字符串中提取電子郵件
我怎麼能在PL/SQL中做到這一點?
試試這個(regular expression):
select regexp_substr ('sdss [email protected] sdsda sdsds ','[A-Za-z0-9._%+-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}') email from dual
像這樣的事情會很多情況下工作,但遠非完美。我添加了一個字符串,演示了可能會失敗的兩種不同方式,您會注意到它們。編寫能夠捕捉所有可能情況的查詢並不容易,您對「匹配模式」進一步細化的程度取決於您的輸入數據中的電子郵件數量可能會超出正常水平。
在正則表達式中,請注意點(。)必須用反斜槓進行轉義,並且在匹配列表(方括號中的字符列表)內,連字符 - 必須是列表中的第一個或最後一個字符,其他任何地方都是元字符。
在輸出中,注意最後一行;輸入字符串是空的,所以輸出也是空的。
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.
看看這個http://www.orafaq.com/forum/t/189919/ – Petaflop
電子郵件總是最後? – sagi
您可以嘗試搜索@字符串返回的字符串,將它的Len作爲空白區域的入口,然後在完整的sting中抓取該int的ngram標記。這是一個痛苦,但可行,並將永遠是consostant。你有數據樣本嗎? – Merenix