Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

REGEXP_REPLACE How to loop through variable occurrences of a text string

PhilMan2Jan 2 2015 — edited Jan 21 2015

Hello,

I'm using an Oracle 11.g procedure. I found an example of REGEXP_REPLACE with only two arguments (input and pattern) and created a procedure based on that example. The Replace function works, but not optimally. I'm trying to use REGEXP_REPLACE in order to loop through a variable number of occurrences of a particular text string within a CLOB local variable.  The string occurs after the text base64, (base64 comma) and before the text " /> (double-quote space forward-slash greater-than).  I can make the replace work for a single occurrence, but I can't make it loop properly.  These embedded strings comprise images that have been inserted into an Apex rich-text field.  That rich-text field is assigned to the CLOB p_html.

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;

What I'd like to see for data results are:

one start here and this is the end one

two start here and this is the end two

The results I'm getting are:

two start here and this is the end two

two start here and this is the end two

Thanks very much for looking at this.

This post has been answered by Frank Kulash on Jan 2 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2015
Added on Jan 2 2015
6 comments
2,604 views