0

How Can I Search and Replace text using Regular Expressions in Openoffice macros?

I am trying

oDoc = ThisComponent

Public Function findReplace(oDoc As Object, findStr As String, replaceStr As String) As Integer 
   oSearch = oDoc.createSearchDescriptor
   oSearch.searchAll = False
   oSearch.SearchString = findStr
   oSearch.ReplaceString = replaceStr
   oDoc.replaceAll(oSearch)
End Function


findReplace(oDoc, ".
", "    ")

I make this question because I need to find ".\n" (dot breakline) and replace with other character. In the above code I obtain syntax error.

Also I trying

findReplace(oDoc, "."+chr(13), "    ")

But that does not works

Juan
  • 2,073
  • 3
  • 22
  • 37

1 Answers1

0

To use a regular expression, do this:

oSearch.SearchRegularExpression = True

Searching for newlines is a special case, because the newline is the end of the match, not part of the match. For paragraph breaks, match \.$. For line breaks, use \.\n.

Check out these links:

Community
  • 1
  • 1
Jim K
  • 12,824
  • 2
  • 22
  • 51