Oracle正则表达式仅以下列格式匹配美国电话号码。
(NNN) NNN-NNNN
或NNN-NNN-NNNN
或NNNNNNNNNN
我已经尝试过并且达成了这个目标:
with test as
(
select '(444) 123-6780' as testcol from dual
union
select '444123-6780' from dual
union
select '6741236780' from dual
union
select '(445) 123-6781' from dual
union
select '447-127-6787' from dual
union
select '447-127-3333333333' from dual
)
SELECT *
FROM test
WHERE REGEXP_LIKE(testcol, '^\(?\d{3}\)?([[:blank:]|-])?\d{3}-?\d{4}$');
结果:
(444) 123-6780 -- valid
(445) 123-6781 -- valid
444123-6780 -- not valid
447-127-6787 -- valid
6741236780 -- valid
如您所见,我收到了444123-6780
(NNNNNN-NNNN
)格式,
我不需要。
有没有办法阻止上述格式不匹配?
答案 0 :(得分:1)
REGEXP_LIKE(testcol,'^(\(\d{3}\))([[:blank:]])\d{3}-\d{4}$|^\d{3}(-)\d{3}(-)\d{4}$|^\d{10}$')
答案 1 :(得分:0)
试试这个注册表..它会帮助你
REGEXP_LIKE(testcol,'^\([0-9]{3}\)[:space:]?[0-9]{3}(-|[:space:])?[0-9]{4}$|^[0-9]{3}-?[0-9]{3}-?[0-9]{4}$')
来自:http://psoug.org/snippet/Regular-Expressions--RegExp-examples-3_859.htm