使用 REGEXP_REPLACE 替换开始字符串和结束字符串之间的任何内容(包括特殊字符)
replace anything between a start string and end string (including special char) using REGEXP_REPLACE
update customer set cust_info= REGEXP_REPLACE(cust_info,'<start><cust_name><start><cust_name><this field has long string><end>','') where user_id=123;
ORA-12733: 正则表达式太长
所以我尝试了 REGEXP_REPLACE(cust_info,'<start>[A-Z0-9_](*.?)<end>','');
但没有用。
我想将 <start>
字符串和 <end>
字符串之间的任何内容替换为空白。
(即删除 <start>
和 <end>
之间的任何内容)。
PS:- cust_info 列包含带有 html 标签的长字符串。
你的正则表达式似乎不对试试表达式 <start>(.)*?<end>
WITH da AS (
SELECT '<start><cust_name><start><cust_name><this field has long string><end>' AS cust_info FROM dual UNION ALL
SELECT 'name_test' AS cust_info FROM dual
) SELECT REGEXP_REPLACE(cust_info,'<start>(.)*?<end>','') FROM da;
尝试
UPDATE
customer
SET
cust_info = REGEXP_REPLACE(cust_info, '<start>(.)*?<end>', '')
WHERE
user_id = 123;
解释:-
<start> //Matches literal <start>
(.) //Matches any character except linebreaks
* //Matches 0 or more of the preceding token of (.)
? //Makes the preceding quantifier lazy, causing it to match as few characters as possible
<end> //Matches literal <end>
如果您的字符串有换行符,请使用 match_parameter 将其纳入考虑
REGEXP_REPLACE ( cust_info, '<start>(.*?)*?<end>' , '' , 1 , 1 , 'n' )
基于:
REGEXP_REPLACE ( source_string, search_pattern
[, replacement_string
[, star_position
[, nth_occurrence
[, match_parameter ]
]
]
]
)
因此:
UPDATE
customer
SET
cust_info = REGEXP_REPLACE ( ID_DESC, '<start>(.*?)*?<end>' , '' , 1 , 1 , 'n' )
WHERE
user_id = 123;
update customer set cust_info= REGEXP_REPLACE(cust_info,'<start><cust_name><start><cust_name><this field has long string><end>','') where user_id=123;
ORA-12733: 正则表达式太长
所以我尝试了 REGEXP_REPLACE(cust_info,'<start>[A-Z0-9_](*.?)<end>','');
但没有用。
我想将 <start>
字符串和 <end>
字符串之间的任何内容替换为空白。
(即删除 <start>
和 <end>
之间的任何内容)。
PS:- cust_info 列包含带有 html 标签的长字符串。
你的正则表达式似乎不对试试表达式 <start>(.)*?<end>
WITH da AS (
SELECT '<start><cust_name><start><cust_name><this field has long string><end>' AS cust_info FROM dual UNION ALL
SELECT 'name_test' AS cust_info FROM dual
) SELECT REGEXP_REPLACE(cust_info,'<start>(.)*?<end>','') FROM da;
尝试
UPDATE
customer
SET
cust_info = REGEXP_REPLACE(cust_info, '<start>(.)*?<end>', '')
WHERE
user_id = 123;
解释:-
<start> //Matches literal <start>
(.) //Matches any character except linebreaks
* //Matches 0 or more of the preceding token of (.)
? //Makes the preceding quantifier lazy, causing it to match as few characters as possible
<end> //Matches literal <end>
如果您的字符串有换行符,请使用 match_parameter 将其纳入考虑
REGEXP_REPLACE ( cust_info, '<start>(.*?)*?<end>' , '' , 1 , 1 , 'n' )
基于:
REGEXP_REPLACE ( source_string, search_pattern
[, replacement_string
[, star_position
[, nth_occurrence
[, match_parameter ]
]
]
]
)
因此:
UPDATE
customer
SET
cust_info = REGEXP_REPLACE ( ID_DESC, '<start>(.*?)*?<end>' , '' , 1 , 1 , 'n' )
WHERE
user_id = 123;