Libreoffice writer: Macro to search and replace textstring with referencemark

I have two different sub’s that individually work pretty well, my problem is, I do not know how to combine them. My aim is to find certain text patterns in a writer ("\cite{xyz}" and replace them with a reference mark.

Here is my routine to replace a selected text into a reference mark:

'************************* Create a new reference ***************************
Sub subEventReference
dim oRefField as object
oDoc = ThisComponent
oRefMarks = oDoc.Referencemarks

oRefField = oDoc.createInstance("")
oSel = oDoc.getCurrentSelection().getByIndex(0)
'sSelection = "JR_cite_1_"+oSel.getString
sSelection = oSel.getString

End sub

' ********************* Create the field (sub routine) ***********************
Sub subCreate(oField as object, sText as string)
dim sRefname as string

oField.setName(sText, oRefField)
oDoc.currentController.ViewCursor.Text.insertTextContent(oDoc.currentController.ViewCursor, oField, True)
End sub

And here is my routine to search for a specific text pattern:

Sub searchforpattern

Dim oDescriptor  'The search descriptor
Dim oFound       'The found range
dim oRefField as object
oDoc = ThisComponent

  oDescriptor = ThisComponent.createSearchDescriptor()
  With oDescriptor
    .SearchString = "\\cite\{JR_cite_1_.*\}"
    .SearchRegularExpression = True
    .SearchCaseSensitive = true  'So setting one to False is redundant
  End With

  ' Find the first one
  oFound = ThisComponent.findFirst(oDescriptor)
  Do While Not IsNull(oFound)
   ' here I need to select the textpattern and call the create reference function   
    oFound = ThisComponent.findNext(oFound.End, oDescriptor)

End Sub

I can find my pattern, however I have no idea how to select the text and call the funtion to create a reference.

Hopefully someone with better knowledge can help me.