Apache OpenOffice (AOO) Bugzilla – Issue 78855
Search regular expression with "[" and "]"
Last modified: 2013-02-24 21:09:06 UTC
I think there is a problem with a regular expression search. I search all words between "[" and "]" in a textDocument. Thus, my regular expression is "\[[^\[] *\]". With GUI version the find function is Ok. But when I try to use the API, it do not work correctly. I think that OO finds all words, because if I have 5 words between "[" and "]", OO gives me 5 TextRange in the result. but when i try to get the text with getString() methode, OO alwas gives me "]". If try the same search with word between "@" ( with "@[^@]*@" regular expression), OO finds all results and when I use the getString() methode it gives me the good word.
cellma: Please specify the version of OOo you are referring to.
Excuse me. It's 2.2 version.
jsc -> tl: seems to be one for the writer
TL->cellma: please also add a sample document, along with the code your are using to search for the regular expressions.
String expression = "\[[^\[] *\]"; // "@[^@]*@" XReplaceable xReplaceable = UnoRuntime.queryInterface(XReplaceable.class, mxDoc); XReplaceDescriptor xRepDesc = xReplaceable.createReplaceDescriptor(); xRepDesc.setSearchString(expression); xRepDesc.setPropertyValue("SearchRegularExpression", new Boolean(true)); XIndexAcess resListe = xReplaceable.findAll(xRepDesc); ArrayList xTextRangeListe = new ArrayList(); for(i=0;i<resListe.getCount();i++){ XtextRange xTextRange = UnoRuntime.queryInterface (XTextRange.class,resListe.getByIndex(i)); String val = xTextRange.getString(); //always equals to "[" xTextRangeListe.add(xTextRange); }
Created attachment 47249 [details] test with "\[[^\[] *\]". result = "[","[","["
Your macro does not work (I checked with "2.2.1 Multilingual German version WIN XP: [680m18(Build9161)]"), please attach a sample document with a working macro in it and some explication why your believe that your macro should work for your needs.
My code is extracted from java program. It's not a macro and I don't know how to program a macro. This program do work in my application but with "#[^#]*#" as regular expression and not with "\[[^\[] *\]" That's why I can get all words between # in a document but not between [ and ] !
set target from 2.x to 3.x according to http://wiki.services.openoffice.org/wiki/Target_3x
SBA: This issue has a target set but is still in state of "Unconfirmed". Please re-check with OOo 3.0 or younger if it is (still) valid. Then confirm it or set an appropriate resolution. Thank you.
worksforme. Sub findwords oDoc = thisComponent oSearch = oDoc.createSearchDescriptor() oSearch.setSearchString("\[[^\[]*\]") oSearch.SearchRegularExpression = true oResults = oDoc.findAll(oSearch) for i=0 to oResults.count-1 oMatch=oResults.getByIndex(i) print "found: "+ oMatch.getString next i End Sub works as expected.
closing. Feel free to reopen if you can still reproduce in a current version, but please provide a complete testcase to ease reproducing the issue.