正则表达式替换以删除字符串前缀中的数字

时间:2016-06-27 12:38:43

标签: oracle replace expression

如何删除字符串' Tech search'?

之前的数字
'502402849 - Tech search;502489756 - world wide;123698745 - Tech search to'

注意: - 仅限'技术搜索'不是之前'技术搜索到'

3 个答案:

答案 0 :(得分:0)

可用于匹配您要替换的数字的一个正则表达式是:

\d+\s-\sTech search;

SELECT REGEXP_REPLACE (col, '\d+\s-\sTech search(;|$)', '')

在这里测试正则表达式:

enter image description here

答案 1 :(得分:0)

查询1

WITH data ( value ) AS (
  SELECT '502402849 - Tech search;502489756 - world wide;123698745 - Tech search to'
  FROM   DUAL
)
SELECT REGEXP_REPLACE( value, '^\d+' ) AS out
FROM   data;

<强>输出

OUTPUT                                                         
----------------------------------------------------------------
 - Tech search;502489756 - world wide;123698745 - Tech search to 

查询2

WITH data ( value ) AS (
  SELECT '502402849 - Tech search;502489756 - world wide;123698745 - Tech search to'
  FROM   DUAL
)
SELECT REGEXP_REPLACE( value, '\d+\s*-\s*(Tech search(;|$))', '\1' ) AS output
FROM   data;

<强>输出

OUTPUT                                                      
-------------------------------------------------------------
Tech search;502489756 - world wide;123698745 - Tech search to 

查询3

WITH data ( value ) AS (
  SELECT '502402849 - Tech search;502489756 - world wide;123698745 - Tech search to'
  FROM   DUAL
)
SELECT REGEXP_REPLACE( value, '\d+\s*-\s*(Tech search(;|$))' ) AS output
FROM   data;

<强>输出

OUTPUT                                                      
-------------------------------------------------
502489756 - world wide;123698745 - Tech search to 

答案 2 :(得分:0)

regexp_replace(&#39; 502402849 - 技术搜索; 502489756 - 全球范围; 123698745 - 技术搜索到&#39;,&#39; \ d +(?= - 技术搜索;)&#39;,&#39 ;&#39);