Regex 在oracle中提取括号外的数据

Regex 在oracle中提取括号外的数据,regex,oracle,plsql,Regex,Oracle,Plsql,我有这个值:(203)1669 我的要求是提取括号外的数据 SELECT REGEXP_REPLACE(phone_number, '\([[:digit:]]+\)(.*)', '\1') AS newValue FROM your_table 我想对这个Oracle查询使用正则表达式 非常感谢 您可以使用OracleREGEXP\u REPLACE()函数,并匹配括号外的组 SELECT REGEXP_REPLACE(phone_number, '\([[:digit:]]+\)(.*)'

我有这个值:(203)1669

我的要求是提取括号外的数据

SELECT REGEXP_REPLACE(phone_number, '\([[:digit:]]+\)(.*)', '\1') AS newValue
FROM your_table
我想对这个Oracle查询使用正则表达式


非常感谢

您可以使用Oracle
REGEXP\u REPLACE()
函数,并匹配括号外的组

SELECT REGEXP_REPLACE(phone_number, '\([[:digit:]]+\)(.*)', '\1') AS newValue
FROM your_table

对于您提到的模式,这应该是可行的

select  
rtrim(ltrim(substr(phone_number,instr(phone_number,')')+1,length(phone_number)))) 
as derived_phone_no
from 
(select '(123)456' as phone_number from dual union all
 select '(567)99084' as phone_number from dual)

首先我得到
的位置,然后从
的位置得到
substr
+
1
直到字符串的长度。作为最佳实践,您可以使用微调功能。

您可以结合使用SUBSTR和INSTR功能

select substr('(203)1669', instr('(203)1669',')')+1) from dual

本例使用REGEXP_SUBSTR(),并且REGEX显式地遵循您的规范,获取结束参数和行尾之间的4位数字。如果可能有不同的位数,请将一个或多个位数的
{4}
替换为
+

SQL> with tbl(str) as (
      select '(203)1669' from dual
    )
    select regexp_substr(str, '\)(\d{4})$', 1, 1, NULL, 1) nbr
    from tbl;

NBR
----
1669

SQL>

有人试图实现你的愿望吗?模式总是一样的。我的意思是你能得到像
123(456)
Hi@Utsav这样的东西吗?模式总是一样的。(203)XXXX@Shikha-好的。对于您提到的模式,请参见此。为了预防,我添加了
trim
。如果需要,您可以将其删除。您也可以尝试此方法
(电话号码,..[^[:digit:]](.*),\1')
非常感谢您提供快速解决方案!