RegexFind and RegexReplace


RegexReplace dialog would be popup when invoked, by selecting the command from Blacksun/JDT menu or pressing key sequence for Blacksun/RegexReplace command (as defined in the Preferences/Workbench/Keys preference page), in a TextEditor. The dialogs are similar to the standard Eclipse find and replace dialog but it accept a regular expression as search pattern and allow back references in the replace string. The search and replace function is backed by org.apache.oro.text.perl.Perl5Util package, so you can expect most functionity as in Perl regex.

The UP_ARROW button trace back to match locations found previously.

If RegexReplace dialog is popup when there is a selection across more than one line, the action is restricted to the selected region. Find and replace would be performed only inside the region. Selection on a single line would be taken as search pattern and search region would be the whole buffer.

RegexReplaceDialog-2.png RegexReplaceDialog-Error-2.png



RegexFind dialog popup when the command is invoked (selected from Blacksun/JDT menu or pressing key sequence for Blacksun/RegexReplace command) in a TreeViewer or a TableViewer. It provide search only function but it can search backward as well as forward. It is backed by org.apache.oro.text.perl.Perl5Util package, so you can expect most functionity as in Perl regex.


  1. \s+ do not match line breaks
  2. A: Use \s+\n to search beyond line breaks.
  3. Is it possible to confine RegexReplace within a region.
  4. Yes. Select the region accross more than one line before popup the RegexReplace dialog. Operations would be confined to the text selection in the editor when RegexReplace dialog is activated. This is most handy to perform ReplaceAll action for the selected region. Note that in case, the RegexReplace dialog is out of focus and activated again, it reset the region to the new text selection. When no text range is selected when the dialog is activated, it works on the whole buffer. Also, search region is reset to the whole buffer after ReplaceAll action (this is a side effect of popping up the progress dialog).
  5. Is it possible to confine RegexFind to part of the Tree or Table.
  6. Yes for Tree, no for Table. If there is a selection in the active tree viewer when RegexFind is invoked, RegexFind is confined to the elements in initial selection and its children. RegexFind determine the search space when the dialog popup, going out focus and back would not change the search space. RegexFind always search the whole Table.
  7. If you accidentally poping up the RegexFind dialog in a very large tree, it may takes forever to load all the elements, hit the close button to abort and select a smaller region to search.
  8. Why the search pattern typed into the RegexFind dialog reversed in Eclipse 2.1.0 M4-GTK.
  9. The problem is probably due to the GTK library failed to update the caret when there are great delay in the Combo ModifyEvent handler. The delay in the ModifiyEvent hanlder in this case is most probably due to overhead in updating selection in a large tree when performing incremental search. It happens even if the search space is confined to a very small selection. If you type very slowly, you can see the caret in action :( and the text would be correct. This problem does not happen in 2.1.0 M4-Motif. Eclispe 2.0.2-Motif is still the best bet for now.
  10. Why RegexFind dialog cannot popup by hot keys in 2.0.x.
  11. There are various reasons for this. One of which is problem with the 2.0.x key binding. The hot-key sequence is trapped in that viewer by Eclipse. Use the menu. It works fine in 2.1.0 and RegexReplace invoked from editor works fine with accelerator keys in both 2.0.x and 2.1.0.
  12. Even activated from the menu, the RegexFind dialog may fail to popup. Check the console and the Eclipse Error Log for any exceptions and debug messages. Very often, it is due to the fact that the View have not make the TreeViewer or TableViewer available to outsider. RegexReplaceAction use reflection to find a getTreeViewer(), getTableViewer() or getViewer() method to access the viewer in the view. If none of them are available, RegexFind dialog would fail to popup.
  13. So far, Java Package Explorer, Nagivator, Search View, and MethodView, AnnotationView are known to work with RegexFind. Outline pages of the Black-sun editors also work with RegexFind but JavaOutlinePage does not (use MethodView instead).
  14. How to change the accelerator keys that invoke RegexFind and RegexReplace.
  15. In JdtPlugin plugin.xml. They share a single accelerater key seqeuence.
  16. How to put TAB and CR/LF in the replace field of the RegexReplaceDialog.
  17. Use \t, \r, and \n.
  18. I don't want the action to cluster the editor context menu, how can I take it off.
  19. Comment out the popup menu extension viewerContribution item in the JdtPlugin's plugin.xml. The action should still available through accelerator and the Black-sun menu.