Read PDF and extract page range where text occurs more than once?

Hi everyone, I want to extract a page from a PDF file where a text occurred. This is what I did as I found from 1 post here:

Assign int i=1
Use while activity and use condition i<= pdfPageCount.
Inside while using the Read PDF Text activity and set the page range to i.ToString.
Now add your condition to check your particular string on that page. (Check it in your pdf text output variable)
if the page contains your string then extract that page using the extract PDF page range
At the end but inside while incrementing i=i+1

However, if a text occurs more than once, I noticed the extract PDF page range only extracts the last page with the text occurring. Is there a way to change this script to get all the pages where a certain text occurs more than once?

Extract page from inside the loop itself, also name it dynamically, may be by adding the looping variable along with the name, so the extracted pages are not replaced.

How do you do that?