【发布时间】:2015-02-27 22:40:00
【问题描述】:
我正在使用 Oracle 11.g 程序。我发现这个REGEXP_REPLACE 的例子只有两个参数(输入和模式)。它有效,但不是最佳的。我正在尝试使用REGEXP_REPLACE 来循环遍历出现在文本 base64, 之后和文本 " /> 之前的特定文本字符串的可变次数强>
我可以让它工作一次,但我不能让它正常循环。
Declare p_html clob;
l_image_clob clob;
l_image_count number;
Begin
p_html := '<p>Some header text base64,one start here and then this is the end one" /></p><p>Some header text base64,two start here and then this is the end two" /></p>';
l_image_count := REGEXP_COUNT(p_html, 'base64', 1, 'i');
If l_image_count > 0 Then
For i In 1..l_image_count Loop
l_image_clob := REGEXP_REPLACE(p_html, '(.*base64,)|(" />.*)');
dbms_output.put_line(l_image_clob);
-- code to process each occurrence individually.
End Loop;
End If;
End;
我希望看到的数据结果是:
one start here and this is the end one
two start here and this is the end two
上面的例子返回:
two start here and this is the end two
two start here and this is the end two
我尝试了几个选项 REXEXP_REPLACE,但我似乎无法使其与变量 i 一起使用。
【问题讨论】:
-
REGEXP_REPLACE()不需要 3 个参数吗?要搜索的字符串、正则表达式和正则表达式的替换。 -
@Barmar 否,使用 2 个参数删除匹配的字符串 documentation
标签: regex plsql oracle11g regexp-replace