I have the following snippet of code, which I created in OOo a while back and which has worked for a long time. However, when In recently tried this code in LibreOffice 4.4.2.2, the search never returned any results:
SearchDesc = Sheet.getColumns().getByIndex(0).createSearchDescriptor
SearchDesc.setSearchString(TextToRegex(strWord))
SearchDesc.SearchRegularExpression = True
SearchDesc.SearchCaseSensitive = False
SearchDesc.SearchWords = True
SearchRes = Sheet.getColumns().getByIndex(0).findFirst(SearchDesc)
It seems that the regex is at fault, as the following code works (for direct matches, that is):
SearchDesc = Sheet.getColumns().getByIndex(0).createSearchDescriptor
SearchDesc.setSearchString(strWord)
SearchDesc.SearchCaseSensitive = False
SearchDesc.SearchWords = True
SearchRes = Sheet.getColumns().getByIndex(0).findFirst(SearchDesc)
Trying a somewhat more crude regex also works:
SearchDesc = Sheet.getColumns().getByIndex(0).createSearchDescriptor
SearchDesc.setSearchString(".*" + strWord + ".*")
SearchDesc.SearchRegularExpression = True
SearchDesc.SearchCaseSensitive = False
SearchDesc.SearchWords = True
SearchRes = Sheet.getColumns().getByIndex(0).findFirst(SearchDesc)
What’s the issue here? It seems the TextToRegex() function returns a regex which doesn’t match the original text…